Python – API.trends_available() in Tweepy
Last Updated :
11 Jun, 2020
Twitter is a popular social network where users share messages called tweets. Twitter allows us to mine the data of any user using Twitter API or Tweepy. The data will be tweets extracted from the user. The first thing to do is get the consumer key, consumer secret, access key and access secret from twitter developer available easily for each user. These keys will help the API for authentication.
API.trends_available()
The trends_available()
method of the API
class in Tweepy module is used to fetch the locations that Twitter has trending topic information for.
Syntax : API.trends_available()
Parameters : None
Returns : an object of class JSON
Example 1 :
import tweepy
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
trends = api.trends_available()
print ( "The number of locations available are : " + str ( len (trends)))
|
Output :
The number of locations available are : 467
Example 2 :
trends = api.trends_available()
print ( "Some of the locations are : " )
for i in range ( 0 , 200 , 20 ):
print ( "Place : " + trends[i][ 'name' ] +
", Country : " + trends[i][ 'country' ])
|
Output :
Some of the locations are :
Place : Worldwide, Country :
Place : Leeds, Country : United Kingdom
Place : Mexico City, Country : Mexico
Place : Mendoza, Country : Argentina
Place : Belo Horizonte, Country : Brazil
Place : Lodz, Country : Poland
Place : Dortmund, Country : Germany
Place : Utrecht, Country : Netherlands
Place : Oslo, Country : Norway
Place : Palembang, Country : Indonesia
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...