Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter API - Get number of followers of followers

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

like image 264
user1893354 Avatar asked Jul 03 '13 14:07

user1893354


People also ask

How do I get followers in tweepy API?

API.followers () The followers () method of the API class in Tweepy module is used to get the specified user’s followers ordered in which they were added. Syntax : API.followers (id / user_id / screen_name) Parameters : Only use one of the 3 options:

How to count the number of followers on a list?

Example 2: More than 20 followers can be accessed using the Cursor () method. Example 3: Counting the number of followers. print(screen_name + " has " + str(count) + " followers.") geeksforgeeks has 17338 followers.

How to get user’s followers ordered in which they were added?

The followers () method of the API class in Tweepy module is used to get the specified user’s followers ordered in which they were added. Example 1 : The followers () method returns the 20 most recent followers.

How do I get my twitter follower/unfollower stats in Python?

You can install it as always with pip: The TwitterAPI package makes it easy to download your tweet and follower/unfollower stats from Twitter. The TwitterStats package makes it even more convenient to access these data. If you enjoyed this article, consider following me on Twitter where I regularly share tips on Python, SQL and Cloud Computing.


2 Answers

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.

like image 67
alecxe Avatar answered Sep 23 '22 11:09

alecxe


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)
like image 20
Janvi Kirti Kumar Kothari Avatar answered Sep 21 '22 11:09

Janvi Kirti Kumar Kothari