0

I'm using the tweepy twitter API for the first time and need some help please... In the following chunk of code I'm looping over a list of user IDs (stored as 'accounts') and for each account I'm using tweepy.Cursor to find a list of IDs they are following (their 'friends'). I check for matches with accounts I'm following too (stored in 'ids') and then store the matches as a dataframe.

The problem I have is that I keep getting the 'Rate limit reached' error. How do I avoid this please? I'm assuming there is a much smarter way to do this!

Thanks.

df_list = []

for account in accounts:
  friends = []
  for page in tweepy.Cursor(api.friends_ids, id=account).pages():
    friends.extend(page)

  friends = pd.Series(friends)
  matches = friends[friends.isin(ids)]

  d = {'friend_id' : account, 'common_friends' : matches}
  matches = pd.DataFrame(data=d)
  df_list.append(matches)

final_df = pd.concat(df_list)
astro person
  • 381
  • 5
  • 16
  • Probable duplicate of [Avoid Twitter API limitation with Tweepy](https://stackoverflow.com/questions/21308762/avoid-twitter-api-limitation-with-tweepy) – ralex Apr 02 '19 at 19:21
  • @ralex I came across that post before but I don’t understand the solutions. I feel at a much earlier stage in my tweepy/python experience. – astro person Apr 02 '19 at 23:10

1 Answers1

1

You can use:

api = tweepy.API(auth, wait_on_rate_limit=True)

When you reach maximum request then stop and wait until can send the request again.