Search code examples
pythontwittertweepytwitter-streaming-api

Twitter Streaming: Get trends on Twitter on the basis of countries


I am using tweepy to get twitter tweets. I want to get the current trends based on the country of my choice. My code is as follows:

import tweepy
file = open("data.txt", 'r')
authentication = tweepy.OAuthHandler('consumer_key', 'consumer_secret')
authentication.set_access_token('access_token', 'access_secret')
api = tweepy.API(authentication)
trends = api.trends_available()
for trend in trends:
    print trend

The code above gives me a list of countries. I want to use the list to check the current trends in the country. How do I extract the trending hashtags for these countries?

I came across this question but it has no answers.


Solution

  • you are using the wrong endpoint for this job you have to use this which translates to tweepy api.trends_place(woeid) and provide an woeid as described in this page which you can get also from api.trends_available() results.