pythontwittertweepyhashtagtrending

Find trending tweets, with Tweepy, for a specific keyword


Bear with me, since I am still learning Python..

I want to be able to see the most trending tweets for a specific hashtag. I am able to find trending tweets and I am able to find tweets with a specific hashtag but I am at a loss when trying to combine these two.

import tweepy

CONSUMER_KEY = 'key'
CONSUMER_SECRET = 'secret'
OAUTH_TOKEN = 'key'
OAUTH_TOKEN_SECRET = 'secret'

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET)

api = tweepy.API(auth)
trends = api.trends_place(1)

search_hashtag = tweepy.Cursor(api.search, q='hashtag').items(5000)

for tweet in search_hashtag:
    print json.dumps(tweet)

print json.dumps(trends, indent=1)

This is what i have now that is working..

Thanks!


Solution

  • From: https://dev.twitter.com/rest/public/search

    It allows queries against the indices of recent or popular Tweets and behaves similarly to, but not exactly like the Search feature available in Twitter mobile or web clients, such as Twitter.com search. The Twitter Search API searches against a sampling of recent Tweets published in the past 7 days.

    Therefore, you are pretty much already getting what you want. These are actually trending tweets for specific hashtag/topic.

    https://dev.twitter.com/rest/reference/get/trends/place is simply meant to get trending topics for specific location, but from your question it seems you want to search by some specific topic, not the one that is currently tr