【问题标题】:Twitter API - Get number of followers of followersTwitter API - 获取关注者的关注者数量
【发布时间】:2013-07-01 07:37:43
【问题描述】:
我正在尝试获取特定帐户的每个关注者的关注者数量(目标是找到最具影响力的关注者)。我在 Python 中使用 Tweepy,但我遇到了 API 速率限制,在我被切断之前我只能获得 5 个关注者的关注者数量。我正在查看的帐户有大约 2000 个关注者。有没有办法解决这个问题?
我的代码 sn-p 是
ids = api.followers_ids(account_name)
for id in ids:
more = api.followers_ids(id)
print len(more)
谢谢
【问题讨论】:
标签:
python
twitter
tweepy
rate-limiting
【解决方案1】:
您无需获取所有用户关注者即可统计他们。使用followers_count 属性。例如:
import tweepy
auth = tweepy.OAuthHandler(..., ...)
auth.set_access_token(..., ...)
api = tweepy.API(auth)
for user in tweepy.Cursor(api.followers, screen_name="twitter").items():
print user.screen_name, user.followers_count
打印:
...
pizzerialoso 0
Mario98Y 0
sumankumarjana 1
realattorneylaw 3056
JaluSeptyan 10
andhita_khanza 18
...
希望对您有所帮助。
【解决方案2】:
这行得通。但是,我有一个替代解决方案,可以获取基于特定用户的定量信息,例如关注者数量、状态等。
import tweepy
auth = tweepy.OAuthHandler(..., ...)
auth.set_access_token(..., ...)
api = tweepy.API(auth)
follower_count = api.get_user('twitter').followers_count
print(follower_count)