【发布时间】:2020-08-07 01:28:13
【问题描述】:
我正在尝试从@realDonaldTrump 获取所有 50k 条推文。我知道 twitter api 请求有限制,所以我使用 max_id=oldest。但我只收到 995 条推文。
import tweepy as tweepy
consumerKey = "xxx"
consumerSecret = "xxx"
accessToken = "xxx"
accessTokenSecret = "xxx"
auth = tweepy.OAuthHandler(consumerKey, consumerSecret)
auth.set_access_token(accessToken, accessTokenSecret)
api = tweepy.API(auth, wait_on_rate_limit=True)
alltweets = []
username="@realDonaldTrump"
new_tweets = api.user_timeline(username, tweet_mode = 'extended', count=200)
alltweets.extend(new_tweets)
oldest = alltweets[-1].id - 1
while len(new_tweets) > 0:
print(f"getting tweets before {oldest}")
new_tweets = api.user_timeline(username, max_id=oldest,tweet_mode = 'extended', count=200)
alltweets.extend(new_tweets)
oldest = alltweets[-1].id - 1
print(f"...{len(alltweets)} tweets downloaded so far")
outtweets = [[tweet.id_str, tweet.created_at, tweet.full_text] for tweet in alltweets]
【问题讨论】: