skip to Main Content

I am starting to make a python program to get user locations, I’ve never worked with the twitter API and I’ve looked at the documentation but I don’t understand much. I’m using tweepy, can anyone tell me how I can do this? I’ve got the basics down, I found a project on github on how to download a user’s tweets and I understand most of it.

3

Answers


  1. I don’t believe that Tweepy can get user location data; have you had a look the documentation?

    You may be better off with Twython which can call the get statuses/user_timeline API call?

    Also bear in mind that for privacy reasons twitter won’t give you a lat/long for users; the user has their location made less accurate, usually referencing their “neighborhood”.

    Login or Signup to reply.
  2. Once you have the twitter (JSON) search results, you can extract the location information, if it’s available. Not all twitter users have included their location information.

    for tweet in results:
        print(tweet.get('user', {}).get('location', {}))
    

    After analyzing the twitter API responses for various queries, I think getting the tweet location is not possible since the API does not include it in the JSON response.

    Login or Signup to reply.
  3. Once you have a tweet, the tweet includes a user, which belongs to the user model. To call the location just do the following

    tweet.user.location

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