【问题标题】:Twitter user_timeline not returning enough tweetsTwitter user_timeline 没有返回足够的推文
【发布时间】:2018-06-29 22:33:38
【问题描述】:

我目前在 python 中使用 GET statuses/user_timeline twitter API 来检索推文,它在 docs 中说 此方法最多只能返回用户最近的 3,200 条推文当我运行它时,它只返回 100-150。

我如何让它返回比现在更多的推文?

提前致谢

【问题讨论】:

    标签: python twitter


    【解决方案1】:

    您必须编写代码才能使用时间线。 Twitter 的 Working with timelines documentation 讨论了 Twitter 时间线如何以及为何如此运作。

    基本上,将您的count 设置为最大数量(200)并使用since_id 和max_id 来管理阅读每一页。或者,您可以使用现有的库来简化任务。这是一个使用tweepy 库的示例。

    consumer_key = "<your consumer_key>"
    consumer_secret = "<your consumer_secret>"
    access_token = "<your access_token>"
    access_token_secret = "<your access_token_secret>"
    
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    
    api = tweepy.API(auth)
    
    for status in tweepy.Cursor(api.user_timeline, "JoeMayo").items():
        print('status_id: {}, text: {}'.format(status.id, status.text.encode('utf-8')))
    

    【讨论】:

    • 仍然为@realDonaldTrump 有时此代码返回 160 条推文,有时返回 220 条推文
    猜你喜欢
    • 2012-12-10
    • 1970-01-01
    • 1970-01-01
    • 2018-11-18
    • 2019-07-02
    • 2015-05-15
    • 2011-08-25
    • 2017-08-22
    • 1970-01-01
    相关资源
    最近更新 更多