Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 862
Luispe Reyes Avatar asked Apr 08 '16 01:04

Luispe Reyes


People also ask

Can you find a twitter users location?

Twitter won't show any location information unless you've opted in to the feature, and have allowed your device or browser to transmit your coordinates to us. If you have chosen to attach location information to your Tweets, your selected location label is displayed underneath the text of the Tweet.

How do you scrape tweets by location?

Scraping by Location When filtering by location there are two options: you can use the near:city tag alongside within:radius or geocode:lat,long,radius . After extensive research I can confirm they yield identical results when used correctly (or should I say, as Twitter interprets them).


2 Answers

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.

like image 120
kmario23 Avatar answered Nov 01 '22 10:11

kmario23


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

like image 32
Armando Suarez Avatar answered Nov 01 '22 12:11

Armando Suarez