0

I'm currently trying to build a list of followers for my account. Ultimately the goal is to automatically follow back any new follower. Looking around at other implementations I'm guessing the best way would be to first compile a list of current followers, then occasionally compile a new list, do a list comparison and then initiate follow commands for any new user ids.

However the account I manage has a few thousand followers, and currently I'm receiving about 300 items every request before the rate limiter kicks in. Other docs imply that this could be 5,000 per request so what am I doing wrong? How can I receive the 5,000? (or is there an alternate way to simply follow back new followers?).

auth = tweepy.OAuthHandler(CONSUMER_KEY,CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY,ACCESS_SECRET)
api = tweepy.API(auth,wait_on_rate_limit=True, wait_on_rate_limit_notify=True)

def limit_handled(cursor):
    while True:
        try:
            yield cursor.next()
        except tweepy.RateLimitError:
            now = datetime.now()
            now_time = now.time()

            print ('Limit Reached - Resuming at {}'.format(now + timedelta(minutes=20)))
            sleep(20 * 60)

def follow_gen():
    for user in limit_handled(tweepy.Cursor(api.followers, count=5000).items()):
            with open('follower_list2.txt','a') as f:
                f.write('{}-{}\n'.format(user.id, user.screen_name))


follow_gen()

I have also tried .pages() instead of .items() but I still seems to only get about 300 ids per request.

1 Answer 1

0

Stupid move on my part - solved it.

api.followers is limited by Tweepy to 100 responses per call. Use api.followers_ids and it works like a dream.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.