Search code examples
twittertweepy

Check the number of times a word or a phrase was tweeted


I have a general question regarding twitter APIs in python - is there a way to get the total number of times a particular word, or phrase were tweeted? Thanks in advance.


Solution

  • You can't get that for the life of Twitter. However, you might be able to the search API to get an idea of how many times over the last 2 weeks, which is the approximate max amount of time the search API goes into the past:

    auth = tweepy.auth.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
    auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
    api = tweepy.API(auth)
    search_results = api.search(q="<your word>")
    

    Then count the number of tweets you get back for an approximation.

    For more info, look at the Tweepy Search API. Also, look at Tweepy Cursors for getting more than the default count of tweets.