3

First of all let me note that this is the first time I am using the Twitter API, so I could be missing something obvious.

What I want to do is get all tweets that include a given hashtag. My research lead me to use the twitter search API. I've tried using it, however I only seem to get about 6 tweets, when I know that the hashtag has thousands of tweets.

So my question is, how do I actually get all of the tweets for a given hashtag? Or at least more than 6 tweets.

For reference, there is the python code I am using to fetch tweets with the #hillarysoqualified hashtag (replace the keys obviously):

from twitter import Twitter, OAuth                                                                                                                                                                                                         

ACCESS_TOKEN = 'access_token'
ACCESS_SECRET = 'access_secret'
CONSUMER_KEY = 'consumer_key'
CONSUMER_SECRET = 'consumer_secret'

oauth = OAuth(ACCESS_TOKEN, ACCESS_SECRET, CONSUMER_KEY, CONSUMER_SECRET)
t = Twitter(auth=oauth)

query = t.search.tweets(q='%23hillarysoqualified')

for s in query['statuses']:
    print(s['created_at'], s['text'], '\n')

2 Answers2

1

It appears I had not read the docs - Twitter search API only gives you tweets from the last week. Hope this helps if someone else tries to do what I did without knowing.

1

yes, the standard search API gives you only access to last 7 days, but you request an access to a premium Search API sandbox for free which gives access to up to 30 days. you can find more information here https://developer.twitter.com/en/docs/tweets/search/overview

Merouane Benthameur
  • 1,765
  • 2
  • 13
  • 21