I am trying to run the following code to search for two pieces of text in tweets:
search_words = ['Samsung', 'Amazon']
tweets = []
for tweet in tweepy.Cursor(api.search, q=search_words).items():
tweets.append(tweet.text)
But this keeps returning:
TweepError: Twitter error response: status code = 429
Which in the documentation states that I am exceeding the rate limit:
Rate limiting of the API is primarily on a per-user basis — or more accurately described, per user access token. If a method allows for 15 requests per rate limit window, then it allows 15 requests per window per access token.
Rate limits are divided into 15 minute intervals. All endpoints require authentication, so there is no concept of unauthenticated calls and rate limits.
Is my search term too broad? Even when I wait for 15 minutes, I still get the same error when I re-run the script, and even when I try to narrow the words used (just to test).
As an aside but related question, how many tweets/how far back in time will api.search return?
EDIT: Looking into this further, I think that the Cursor loop is making me hit the limit (180 per 15 minutes) after the 180th loop. Is there a more efficient way of searching all tweets in one block rather than having to iterate through?