I want to develop a Jupyter Notebook which on executing every time shows the top 10 Twitter trending topics in India in the last 24 hours.
I got everything set up:
auth = tweepy.OAuthHandler(apikey,apisecretkey)
auth.set_access_token(accesskey,accesssecret)
api = tweepy.API(auth)
and when I run trends1 = api.trends_place(23424848)
, it gives:
AttributeError: ‘API’ object has no attribute ‘trends_place’
And if this attribute has been removed then what should I do to get my work done? Please help..
2
Answers
You are getting this error because
api
do not have thistrends_place
attribute.If u check the documentation (https://docs.tweepy.org/en/stable/api.html#trends), you will see that instead of using
api.trends_place()
, the correct syntax isapi.
followed by the attributeget_place_trends()
.So, i suggest the following code to get the desired result:
Note that
top_trends
is an dictionary inside alist
of length 1. Treat it liketop_trends[0]['trends']
and so on to get specific values. Example:To get trending topics near a specific location on Twitter,
Once you’ve set up:
use
trends = api.trends_place(WOEID)
to get the 50 trending topics based on the lWOEID