通过 Tweepy 在 Twitter 中获取所有关注者 ID [英] Get All Follower IDs in Twitter by Tweepy

查看:53
本文介绍了通过 Tweepy 在 Twitter 中获取所有关注者 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以获得像麦当劳这样拥有超过一百万粉丝的帐户的完整粉丝列表?

Is it possible to get the full follower list of an account who has more than one million followers, like McDonald's?

我使用 Tweepy 并遵循以下代码:

I use Tweepy and follow the code:

c = tweepy.Cursor(api.followers_ids, id = 'McDonalds')
ids = []
for page in c.pages():
     ids.append(page)

我也试试这个:

for id in c.items():
    ids.append(id)

但我总是收到超出速率限制"错误,并且只有 5000 个关注者 ID.

But I always got the 'Rate limit exceeded' error and there were only 5000 follower ids.

推荐答案

为了避免速率限制,您可以/应该在下一个关注者页面请求之前等待.看起来很笨拙,但有效:

In order to avoid rate limit, you can/should wait before the next follower page request. Looks hacky, but works:

import time
import tweepy

auth = tweepy.OAuthHandler(..., ...)
auth.set_access_token(..., ...)

api = tweepy.API(auth)

ids = []
for page in tweepy.Cursor(api.followers_ids, screen_name="McDonalds").pages():
    ids.extend(page)
    time.sleep(60)

print len(ids)

希望有所帮助.

这篇关于通过 Tweepy 在 Twitter 中获取所有关注者 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆