[英]python twitter api returns inconsistent number of tweets each second
I'm trying to write my own twitter-fetch api, based on the python-twitter library.我正在尝试基于python-twitter库编写我自己的 twitter-fetch api。 The goal is to fetch the last 5 tweets of Donald Trump.目标是获取唐纳德特朗普的最后 5 条推文。 I'm getting a different number of tweets every other second or so.我每隔一秒左右就会收到不同数量的推文。 Sometimes it's 5 tweets, sometimes it's only 1.有时是 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)))
Has anyone noticed this before with the twitter REST api using another language/package?有没有人在使用另一种语言/包的 twitter REST api 之前注意到这一点?
Has anyone noticed this before with the python-twitter package that I'm using?有没有人在我使用的python-twitter包之前注意到这一点?
This is normal behavior.这是正常行为。 See count
in this doc: https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline.html请参阅此文档中的count
: https : //developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline.html
count
specifies a max limit rather than a promise to deliver a specified number of tweets. count
指定最大限制而不是承诺提供指定数量的推文。 From the 5 tweets that you request, Twitter may cull some for lack of relevance, etc.从您请求的 5 条推文中,Twitter 可能会因缺乏相关性等原因剔除一些。
For your scenario, simply request many more tweets than 5 (ex. 100) and use only the first 5.对于您的场景,只需请求比 5 条(例如 100 条)多得多的推文,并仅使用前 5 条。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.