如何从Tweepy获取坐标?

5
我有以下代码用于检索推文。指定的地理编码是纽约州内的一个区域。但是,当我使用print(json_reply['user']['location'])打印位置时,它将位置打印为荷兰的Voorburg。我猜这是用户在个人资料信息中指定的位置。此外,地理编码始终返回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'])

荷兰的 Voorburg
1个回答

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接