Search code examples
twittertwitter-oauthtwitter4j

getting most popular hashtags using twitter api


I want to retrieve top 10 or top 20 most popular hashtags from twitter api.

How can I do it, is there any direct api for this or should I collect a large dataset using twitter search api and manually collect popular hashtags?


Solution

  • The Twitter API documentation is here.

    Using Tweepy (Recommended Method) :

    import tweepy
    
    consumer_key ="PUT_YOUR_KEY"
    consumer_secret ="PUT_YOUR_KEY"
    access_token ="PUT_YOUR_KEY"
    access_token_secret ="PUT_YOUR_KEY"
    
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    api = tweepy.API(auth)
    tags = api.trends_place(23424848) # 23424848 Corresponds to the Yahoo ID for India. Change this to the location that you require.
    

    If you do not have tweepy installed use :

    pip install tweepy