【问题标题】:python twitter api returns inconsistent number of tweets each secondpython twitter api每秒返回不一致的推文数量
【发布时间】:2019-08-03 04:07:03
【问题描述】:

我正在尝试基于 python-twitter 库编写自己的 twitter-fetch api。目标是获取唐纳德特朗普的最后 5 条推文。我每隔一秒左右就会收到不同数量的推文。有时是 5 条推文,有时只有 1 条。

import twitter

api = twitter.Api(consumer_key=config["credentials"]["key"],
                  consumer_secret=config["credentials"]["secret"],
                  application_only_auth=True,
                  tweet_mode='extended')

tweets = api.GetUserTimeline(
            screen_name="realDonaldTrump",
            count=5)

print("number of tweets: {}".format(len(tweets)))

在使用其他语言/包的 twitter REST api 之前,有没有人注意到这一点?

之前有没有人注意到我正在使用的python-twitter 包?

【问题讨论】:

    标签: python python-twitter twitter-rest-api


    【解决方案1】:

    这是正常行为。请参阅此文档中的counthttps://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline.html

    count 指定最大限制,而不是承诺提供指定数量的推文。 Twitter 可能会从您请求的 5 条推文中剔除一些缺乏相关性等原因。

    对于您的场景,只需请求多于 5 条(例如 100 条)的推文并仅使用前 5 条。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-23
      • 2018-09-15
      • 1970-01-01
      • 1970-01-01
      • 2017-05-24
      • 1970-01-01
      • 2015-06-02
      • 2020-08-19
      相关资源
      最近更新 更多