如何从Tweepy获取坐标?

she*_*158 5 twitter geocoding

我有以下代码来检索推文.指定的地理编码是纽约州内的一个区域.但是,当我使用print(json_reply ['user'] ['location'])打印位置时,它将打印位置为荷兰沃尔堡.我想这是用户在个人资料信息中指定的位置.此外,地理编码始终返回null.我对来自纽约州的推文和坐标很感兴趣.

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'])
Run Code Online (Sandbox Code Playgroud)

荷兰沃尔堡

Tho*_*ltz 2

实际上,您可以使用 tweepy 的搜索 API 来做到这一点。

首先获取place_id通路...

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

然后使用 tweepy 的搜索 API 和place:<place_id>.

tweets = api.search(q='place:23e921b82040ccd6', count=100)
Run Code Online (Sandbox Code Playgroud)

请参阅: https: //dev.twitter.com/rest/public/search-by-place