Hi!
I am using the Premium Search API Full Archive Sandbox to download all tweets with certain hashtags. The problem I’m incurring is that I’m not a trained engineer or developer and I did some trial and error code. I just realized that I’ve unknowingly exceeded my rate limits (I got a 429 error). What can I do now? I don’t have the budget for the paid plan — it’s more of a research project. Do I just have to wait? How long? How can I avoid exceeding the limit again? Here is my code:
from TwitterAPI import TwitterAPI
import csv
SEARCH_TERM = 'my-search-term'
PRODUCT = 'fullarchive'
LABEL = 'my-label'
NEXT = ''
FROM_DATE = '200603220000'
TO_DATE = '201806020000'
api = TwitterAPI("consumer-key",
"consumer-secret",
"token",
"token-secret")
while True:
r = api.request('tweets/search/%s/:%s' % (PRODUCT, LABEL),
{'query':SEARCH_TERM,
'fromDate': FROM_DATE,
'toDate':TO_DATE,
'next': NEXT
}
)
print(r.status_code)
csvFile = open('2006-2018.csv', 'a')
csvWriter = csv.writer(csvFile)
if r.status_code != 200:
break
for item in r:
csvWriter.writerow([item['created_at'],item['user']['screen_name'], item['text'] if 'text' in item else item])
json = r.json()
if 'next' not in json:
break
NEXT = json['next']