skip to Main Content

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


  1. You are getting this error because api do not have this trends_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 is api. followed by the attribute get_place_trends().

    So, i suggest the following code to get the desired result:

    auth = tweepy.OAuthHandler(apikey,apisecretkey)
    auth.set_access_token(accesskey,accesssecret)
    api = tweepy.API(auth)
    
    WOEID = 23424848
    
    top_trends = api.get_place_trends(WOEID)
    

    Note that top_trends is an dictionary inside a list of length 1. Treat it like top_trends[0]['trends'] and so on to get specific values. Example:

    top_trends[0]['trends'][0]['name']
    top_trends[0]['trends'][0]['url']
    top_trends[0]['trends'][0]['promoted_content']
    top_trends[0]['trends'][0]['query']
    top_trends[0]['trends'][0]['tweet_volume']
    
    Login or Signup to reply.
  2. To get trending topics near a specific location on Twitter,

    Once you’ve set up:

    auth = tweepy.OAuthHandler(apikey,apisecretkey)
    auth.set_access_token(accesskey,accesssecret)
    api = tweepy.API(auth)
    

    use trends = api.trends_place(WOEID) to get the 50 trending topics based on the lWOEID

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search