Python 使用tweepy获取多个给定用户的所有好友
我正在尝试整理一份名单,列出我的朋友在twitter上关注的所有朋友,使用tweepy的朋友的朋友。因此,多个给定用户将是我跟踪的用户 我使用光标返回我跟踪的所有用户 然后尝试打印所有用户的好友Python 使用tweepy获取多个给定用户的所有好友,python,twitter,tweepy,Python,Twitter,Tweepy,我正在尝试整理一份名单,列出我的朋友在twitter上关注的所有朋友,使用tweepy的朋友的朋友。因此,多个给定用户将是我跟踪的用户 我使用光标返回我跟踪的所有用户 然后尝试打印所有用户的好友 for friend in tweepy.Cursor(api.friends).items(): print friend.screen_name user = api.get_user(str(friend.screen_name)) for f2 in user.frien
for friend in tweepy.Cursor(api.friends).items():
print friend.screen_name
user = api.get_user(str(friend.screen_name))
for f2 in user.friends():
print f2.screen_name
但是我遇到了几个问题,第一个问题是每个useruser.friend只打印20个朋友。第二个问题是我一直收到速率限制错误。如何修改此代码以处理速率限制并返回每个给定用户的所有好友如果您这样做,您将看到一次最多可以请求5000个好友
for friend in tweepy.Cursor(api.friends).items():
print friend.screen_name
user = api.get_user(str(friend.screen_name))
for f2 in user.friends():
print f2.screen_name
无法逃脱每15分钟15次查找的速率限制。在代码中使用这一行,您将不再收到限制错误消息
#to wait rather than printing the time limit error
api = tweepy.API(auth, wait_on_rate_limit=True)
那么这是否意味着你每分钟只能查找一个朋友?在这种情况下,我就不能导入时间模块并在获得每个用户时睡眠60秒吗?是的,大多数脚本都是这样做的。睡61秒,以防你的时钟跑得太快!