【发布时间】:2018-02-02 17:01:11
【问题描述】:
我需要一个建议。
我正在尝试了解 Twitter API 速率限制。
我有一个包含大约 10000 个 Twitter 句柄的 csv 文件。
我需要下载这些用户的推文和转发。
如果我遍历句柄并下载数据 - 这将如何影响 Twitter 的速率限制?我的脚本可以在不被列入黑名单的情况下拨打多少电话?
这可以用 Stream API 代替吗?
我将为此使用 Python 和 Tweepy。
提前致谢。
【问题讨论】:
我需要一个建议。
我正在尝试了解 Twitter API 速率限制。
我有一个包含大约 10000 个 Twitter 句柄的 csv 文件。
我需要下载这些用户的推文和转发。
如果我遍历句柄并下载数据 - 这将如何影响 Twitter 的速率限制?我的脚本可以在不被列入黑名单的情况下拨打多少电话?
这可以用 Stream API 代替吗?
我将为此使用 Python 和 Tweepy。
提前致谢。
【问题讨论】:
这是可能的,但您需要错开它以遵守速率限制。我使用这样的东西(来自以前的答案:1,2):
alltweets = []
new_tweets = api.user_timeline(screen_name = screen_name,count=200)
# save most recent tweets
alltweets.extend(new_tweets)
# save the id of the oldest tweet less one
oldest = alltweets[-1].id - 1
#keep grabbing tweets until there are no tweets left to grab
while new_tweets:
try:
new_tweets = api.user_timeline(screen_name = screen_name,count=200,max_id=oldest)
except tweepy.TweepError:
time.sleep(60 * 15)
continue
```
【讨论】: