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)