Reputation: 107
Is there any method to fetch tweets over a specific span of time,using twitter streaming API,in python 3? I am working on a project to fetch tweets that are dated from April 2017 to June 2017.But all I get is the real time tweets.The following is my code in python 3.6:
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
access_token = "####"
access_token_secret = "###"
consumer_key = "###"
consumer_secret = "####"
def on_data(self, data):
print (data)
return True
def on_error(self, status):
print (status)
if __name__ == '__main__':
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, l)
stream.filter(track=['earthquake','Mexico','2017'])
What changes shall I do in the above code?
Upvotes: 1
Views: 571
Reputation: 4058
Twitter's Streaming API returns only real-time tweets. So, the answer is no. Use Twitter's REST API -- specifically, the search/tweets endpoint -- to get historical tweets. But, that gets you only the last week's worth of tweets. To get the older tweets that you are interested in you will need to pay for Twitter's Enterprise service.
Upvotes: 1