Search code examples
pythontweepytwitterapi-python

Twitter specific account followes list


This is my code.How can i get more than 200 person with this.I have no idea about APIs.What changes i have to make to get my result (the account i was checking had 15000 followers)

user = api.get_user(screen_name='Calendly')

data = \[x.\_json for x in tweepy.Cusor(user.followers(count=200)).item(200)\]

df = pd.DataFrame(data)

df = df\[\['id', 'name', 'screen_name'\]\]

df.to_csv('followers.csv', index=False)

Solution

  • There are a few typos in the code you provided.

    Moreover, which version of the Twitter API are you using?

    I am going to assume that this is the 1.1 because you use Cursor.

    A few remarks:

    The Cursor(count=...) argument is the maximum number of followers to get per page.

    The items(...) argument is the maximum number of followers to get in total.

    So you can't get more than 200 followers in you set it to 200.

    And if you want all the followers, don't set it at all. But you will have to deal with the Twitter rate limits (15 requests per 15 minuts for this endpoint). Handle the exception by yourself or use the wait_on_rate_limit argument when you initialise the API (but it will take some time if the account has 15 000 followers).

    A very basic example:

    all_followers = []
    
    # Use the good handler and set your tokens here
    api = tweepy.API(tweepy.OAuth1UserHandler(...), wait_on_rate_limit=True)
    
    cursor = tweepy.Cursor(api.get_followers, screen_name='Calendly', count=200)
    
    for follower in cursor.items():
        all_followers.append(follower)
    

    Please note that I did not use list comprehension for readability, but feel free to do so.