下面是我为某些账号(在本例中是@hudsonci)获取twitter追随者的工作代码。
我的问题是,吸引所有这些追随者所需的时间。这个账号有大约1000名追随者...在有速率限制的情况下,我一次只能达到300。所以,获得这个账号的所有关注者需要一个小时以上。我可以想象,对于大客户来说,这将是一个巨大的痛苦。
我正在寻找一些建议,我可以如何改善这一点。我觉得我没有充分利用分页游标,但我不能确定。
任何帮助都是非常感谢的。
#!/usr/bin/env python
# encoding: utf-8
import tweepy
import time
#Twitter API credentials
consumer_key = "mine"
consumer_secret = "mine"
access_key = "mine"
access_secret = "mine"
#authorize twitter, initialize tweepy
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
def handle_errors(cursor):
while True:
try:
yield cursor.next()
except tweepy.TweepError:
time.sleep(20 * 60)
for user in handle_errors(tweepy.Cursor(api.followers,screen_name='hudsonci').items()):
print user.screen_name发布于 2016-09-29 16:50:47
根据the Twitter documentation for followers,您需要使用count参数。
指定尝试检索的ID数,每个不同请求最多5,000个。
因此,添加count=5000应该会对您有所帮助。
发布于 2018-11-15 01:41:13
您一次可以获得300个关注者,因为获取followers对象(而不是仅获取ID)有20个页面限制。如果每个窗口有15个请求,那么就是300个关注者。
https://stackoverflow.com/questions/39755784
复制相似问题