I want to get a user's friends with Tweepy
and there is a limit on the number of friends I can get in a particular time interval. To handle this query limit I've added a condition with try-except. The logic is to let the Tweepy try to get a next friend and if it comes with an error wait for 15 minutes. But I realize the next()
method does not work. What did I do wrong?
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
def get_user_friends(screen_name):
friends = []
for user in tweepy.Cursor(api.friends, screen_name=screen_name).items(200):
friends.append(user.screen_name)
try:
test = user.next() # Here
except:
time.sleep(60 * 15)
continue
return friends