Get twitter followers using tweepy and multiple API keys

Viewed 2903

I have multiple twitter dev keys that I am using to get followers from a list of handles. There are two ways I can do this but have a problem with both. The first:

try:
    ....
    for user in tweepy.Cursor(api.followers, screen_name=screenName).items():
    ....
except tweepy.TweepError as e:

    errorCode = e.message[0]['code']
        if errorCode == 88:
            print "Rate limit exceeded."
            rotateKeys()

The issue here is that every time I rotate keys, the for loop starts from scratch and starts getting the followers again. I tried to get around this but splitting the for loop:

try:
    items = tweepy.Cursor(api.followers, screen_name=s).items()

I then loop through them manually using next(items)

However rotating api keys does not work as the initial call was done with the first API code and will always try to use that one.

I need a way to rotate keys and continue from were the previous left of.

2 Answers
Related