Pulling all of an accounts Twitter followers, currently can only get the 5000 IDs

183 views Asked by At

I have made a code that will mute the followers of a designated twitter account but obviously when pulling the follower IDs I can only get 5000. Is there a way of me continuing to pull more using a 'last seen' method or cursor?

import tweepy
import time

consumer_key = *****
consumer_secret = *****
key = *****
secret = *****

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(key, secret)
api = tweepy.API(auth, wait_on_rate_limit=True)
user_name = 'realdonaldtrump'

def mute():
    muted_users = api.mutes_ids() 
    followers = api.followers_ids(user_name)
    try:
        for x in followers:
            if x in muted_users :
                pass
            else:
                api.create_mute(x)
                time.sleep(5)
    except Exception:
        print('Error')
1

There are 1 answers

0
Andy Piper On BEST ANSWER

Yes, this function does support cursors. From the Tweepy examples, you can use them like this - you’d need to modify this for muting rather than following.

for follower in tweepy.Cursor(api.followers).items():
    follower.follow()

The issue you will hit with an account with a very large number of followers is that the rate limit here is low - 15 calls in 15 minutes - so this will take a very long time to complete. You may also hit account limits for the number of accounts you can mute within a time period.