How to extract the historical tweets from twitter API?
Question: We need the historical tweets for some movies. Right now, we tried the
streaming API and search API from twitter. The streaming API could not give us
a parameter to choose the time range we need and the search API could only
give us data one or two weeks in advance. Is there a way for us to extract the
historical tweets from 2014-05-01 to 2014-07-01 (For example)? I found the
following ways that is possible to do that:

1: Twitter advanced search <https://twitter.com/search-advanced?lang=en> It
could find the search result I need. But how could I download the search
result? Is there anyway to write a code and save the search result?

2:Using the twitter analytic website like topsy. But it also has the
difficulty to save the result.

3: It seems that some packages like twitter4J could help with that:
<http://twitter4j.org/en/code-examples.html> Is there any python or R package
could help us to do that?

4: We need this data to do a research. It is not a good choice to spend a long
time for the extraction of the data. Is there anyway to buy this data from
some professional website?


Answer: You can use the following library <https://github.com/Jefferson-
Henrique/GetOldTweets-python> to get old tweets in Twitter.

Make GetOldTweets-python as the current directory in Python using

    
    
     cd GetOldTweets-python
    

then do the following

In Python,

    
    
    import got
    tweetCriteria = got.manager.TweetCriteria().setQuerySearch('search_term').setSince("2014-05-01").setUntil("2014-07-01").setMaxTweets(10000)
    tweet = got.manager.TweetManager.getTweets(tweetCriteria)[0]
    
    print tweet.text
    

In terminal,

    
    
    python Exporter.py --querysearch 'search_term' --since 2014-05-01 --until 2014-07-01 --maxtweets 10000
    

Replace 'search_term' with the search term.

