Luispe Reyes
Luispe Reyes

Reputation: 81

How to get twitter user's location with tweepy?

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.

Upvotes: 5

Views: 14814

Answers (3)

Armando Suarez
Armando Suarez

Reputation: 29

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

Upvotes: 2

kmario23
kmario23

Reputation: 61345

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.

Upvotes: 3

Ari Cooper-Davis
Ari Cooper-Davis

Reputation: 3485

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".

Upvotes: 0

Related Questions