Twitter API - Get number of followers of followers

2019-05-06 19:42发布

I'm trying to get the number of followers of each follower for a specific account (with the goal of finding the most influencial followers). I'm using Tweepy in Python but I am running into the API rate limits and I can only get the number of followers for 5 followers before I am cut off. The account I'm looking at has about 2000 followers. Is there any way to get around this?

my code snippet is

ids = api.followers_ids(account_name)
for id in ids:
    more = api.followers_ids(id)
    print len(more)

Thanks

2条回答
Animai°情兽
2楼-- · 2019-05-06 20:12

You don't need to get all user followers in order to count them. Use followers_count property. E.g.:

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

Prints:

...
pizzerialoso 0
Mario98Y 0
sumankumarjana 1
realattorneylaw 3056
JaluSeptyan 10
andhita_khanza 18
...

Hope that helps.

查看更多
淡お忘
3楼-- · 2019-05-06 20:17

This works. However, I have an alternate solution which can get specific user based quantitative info such as count of followers, statuses etc.

import tweepy
auth = tweepy.OAuthHandler(..., ...)
auth.set_access_token(..., ...)
api = tweepy.API(auth)

follower_count = api.get_user('twitter').followers_count
print(follower_count)
查看更多
登录 后发表回答