I want all tweets from May 2013 to May 2014 containing a given word.
I looked at the API documentation for GET search/tweets, but it seems it doesn’t allow you to give a time window, only a date and it will retrieve tweets up to 7 days before.
How can I retrieve those tweets in python? (Basically I want to write a script that does what the Twitter advanced search does
2
Answers
According to the The Twitter Search API documentation, the query you want is not possible: https://dev.twitter.com/rest/public/search
Beyond the last 7 days, what you want to achieve can only be done through manually searching an account on Twitter.
You could try twarc
with the advanced search operators you referenced but I am not sure if it will query an entire year per the Twitter Search API documentation.
Although not Python based, one alternative would be to use https://webrecorder.io/
Scroll to the time you want to record or attempt to capture the entire feed. Note the auto scrolling option as well.
You are going to have to dump your Twitter feed to JSON and parse it for the tweets you want. I just put this together for you in Python using the tweepy and json modules.