Samer Aamar Samer Aamar -4 years ago 230
Python Question

Using python, how to use collect tweets (using tweepy) between two dates?

How can i use python and tweepy in order to collect tweets from twitter that are between two given dates?

is there a way to pass from...until... values to the search api?

I need to be able to search back but WITHOUT limitation to a specific user

i am using python and I know that the code should be something like this but i need help to make it work.

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token_key, access_token_secret)
api = tweepy.API(auth)

collection = []
for tweet in tweepy.Cursor(, ???????).items():
collection[] = tweet._json

Answer Source

After long hours of investigations and stabilization i can gladly share my findings.

  • search by geocode: pass the geocode parameter in the 'q' parameter in this format: geocode:"37.781157,-122.398720,500mi" , the double quotes are important. notice that the parameter near is not supported anymore by this api. The geocode gives more flexibility

  • search by timeline: use the parameters "since" and "until" in the following format: "since:2016-08-01 until:2016-08-02"

there is one more important note... twitter don't allow queries with too old dates. I am not sure but i think they give only 10-14 days back. So you cannot query this way for tweets of last month.


for status in tweepy.Cursor(,
                       q='geocode:"37.781157,-122.398720,1mi" since:2016-08-01 until:2016-08-02 include:retweets',
    tweet_id =
    tweet_json = status._json
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download