How to get coordinates from Tweepy?

I have the following code for receiving tweets. The specified geocode is an area in New York State. However, when I print the location using print (json_reply ['user'] ['location']), it prints the location in Voorburg, Netherlands. I assume this is the location specified by the user in the profile information. In addition, the geocode always returns null. I'm interested in tweets from New York State along with the coordinates.

tweets = api.search(q='xyz', lang='en', since='2016-11-02',until='2016-11-06', geocode='43,-75,90km', count=1) json_str = json.dumps(tweets[0]._json) print(json_str) json_reply = json.loads(json_str) print(json_reply['text']) print(json_reply['created_at']) print(json_reply['user']['location']) print(json_reply['geo']) 

Voorburg, Netherlands

+5
source share
1 answer

You can do this using the tweepy search API.

First get place_id via ...

 >>> places = api.geo_search(lat='43', long='-75', max_results=10) >>> places[0].id u'23e921b82040ccd6' 

Then use the tweepy search API with place:<place_id> .

 tweets = api.search(q='place:23e921b82040ccd6', count=100) 

See: https://dev.twitter.com/rest/public/search-by-place

+2
source

Source: https://habr.com/ru/post/1259622/


All Articles