推文的 Twitter API 位置 [英] Twitter API location of tweets
问题描述
我正在构思一个新的网站创意,让访问者可以在地图上查看发生了某些事情的地方.我想使用 Twitter,因为有人使用特定的主题标签发推文.我想使用 API 捕获该推文并找到该推文的来源位置.这可能吗?
I'm thinking up a new website idea which would allow a visitor to view on a map where certain things have happened. I want to use Twitter, with the idea that someone tweets using a specific hashtag. I want to capture that tweet using the API and find the location of where the tweet came from. Is this possible?
推荐答案
这是可能的.然而,有很多推文(实际上是大多数)没有获得任何位置,并且不可能为这些推文获得它.要定位,用户必须在其帐户参数中启用位置并在发布推文时提供其位置,但大多数推文不会这样做.
It is possible. However there are lots of tweets (a majority in reality) which do not get any location and it is impossible to get it for these ones. To be located, a user must enable location in its account parameters and give its location with the tweet while posting it but a majority of tweeps do not do that.
要检索推文位置,您只需使用 相应的 Twitter API 端点(GET statuses/show/:id
).获得推文后,搜索其 "coordinates"
字段.该字段有一个子字段,也称为 "coordinates"
.这个子字段是一个包含两个数字的列表:[longitude, latitude]
.有关更多信息,请参阅有关 tweets 和 坐标.
For retrieving tweets location, you just have to download the tweet with the corresponding Twitter API endpoint (GET statuses/show/:id
). Once you get the tweet, search its "coordinates"
field. This field has got a subfield also called "coordinates"
. This subfield is a list with two numbers : [longitude, latitude]
. For further information, refer to the Twitter Developers documentation about tweets and coordinates.
这篇关于推文的 Twitter API 位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!