是否可以通过 Twitter API 使用 Tweepy 下载 10000 个用户的推文和转推?
Is it possible to download tweets and retweets of 10000 users with Tweepy through Twitter API?
我需要一个建议。
我正在尝试了解 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
```
我需要一个建议。
我正在尝试了解 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
```