是 - twitter只允许您一次查找100条推文,但您可以在此之后立即查找另外100条推文。唯一值得关注的是速率限制 - 您受限于您可以在每15分钟窗口中对API进行的调用次数。幸运的是,当您使用wait_on_rate_limit=True
创建API时,tweepy能够优雅地处理此问题。我们所需要做的就是将推特ID的完整列表分成100个或更少的批次(假设您有130个 - 第二个批次只应该是最终的30个),然后每次只查看一个。请尝试以下操作:
import tweepy
def lookup_tweets(tweet_IDs, api):
full_tweets = []
tweet_count = len(tweet_IDs)
try:
for i in range((tweet_count/100) + 1):
# Catch the last group if it is less than 100 tweets
end_loc = min((i + 1) * 100, tweet_count)
full_tweets.extend(
api.statuses_lookup(id=tweet_IDs[i * 100:end_loc])
)
return full_tweets
except tweepy.TweepError:
print 'Something went wrong, quitting...'
consumer_key = 'XXX'
consumer_secret = 'XXX'
access_token = 'XXX'
access_token_secret = 'XXX'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
# do whatever it is to get por.TweetID - the list of all IDs to look up
results = lookup_tweets(por.TweetID, api)
for tweet in results:
if tweet:
print tweet.text
谢谢。它是一块蛋糕:) –
不用担心朋友。如果它解决了您的问题,您可以使用它左侧的勾号将其标记为答案 – asongtoruin