【问题标题】:How to auto follow someone with Twython如何使用 Twython 自动关注某人
【发布时间】:2016-05-30 08:47:47
【问题描述】:

我正在制作一个机器人,它会自动转发和收藏任何包含关键字“澳大利亚”的内容

我成功地自动转发和收藏这条推文,但我不知道如何自动关注它们(关注我自动转发的每个人)

search_results = twitter.search(q='Australia', count=10)
try:
    for tweet in search_results["statuses"]:
        try:

            twitter.retweet(id = tweet["id_str"])
            twitter.create_favorite(id = tweet["id_str"])
            twitter.create_friendship(user_id=?????)
        except TwythonError as e:
            print (e)
except TwythonError as e:
        print (e)

【问题讨论】:

    标签: python tweets twython


    【解决方案1】:

    经过大量尝试发现了这个。试试下面的

    twitter = Twython(consumer_key,consumer_secret, access_token, access_secret)
    search_results = twitter.search(q='Australia', count=10)
    try:
        for tweet in search_results["statuses"]:
            try:
                twitter.retweet(id = tweet["id_str"])
                twitter.create_favorite(id = tweet["id_str"])
                st=tweet["entities"]["user_mentions"]
                if st != []:
                    twitter.create_friendship(screen_name=st[0]["screen_name"])
            except TwythonError as e:
                print e
    except TwythonError as e:
            print e
    

    使用screen_name 跟随相应的句柄。

    【讨论】:

    • 天哪,这确实有效!现在我需要弄清楚它为什么起作用!我给了你一个赞成票和勾号:D
    猜你喜欢
    • 2016-10-20
    • 2011-08-23
    • 2016-07-26
    • 2015-05-19
    • 1970-01-01
    • 2018-11-09
    • 1970-01-01
    • 1970-01-01
    • 2016-07-23
    相关资源
    最近更新 更多