2016-11-12 67 views
5

我有以下用於檢索推文的代碼。指定的地理編碼是紐約州內的一個地區。但是,當我使用print(json_reply ['user'] ['location'])打印位置時,它將打印位置爲荷蘭Voorburg。我想這是用戶在配置文件信息中指定的位置。此外,地理編碼總是返回null。我對紐約州的Tweets和座標感興趣。如何從Tweepy獲取座標?

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']) 

沃爾堡,荷蘭

回答

2

實際上,你可以用tweepy的搜索API做到這一點。

首先獲得place_id通過...

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

然後使用tweepy的搜索API與place:<place_id>

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

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