简体   繁体   English

坐标字段Twitter Streaming API

[英]Coordinates field Twitter Streaming api

I am trying to use Twitter streaming api to collect filtered tweets with some coordinates so that I can map them. 我正在尝试使用Twitter流API收集具有某些坐标的过滤后的tweet,以便可以对其进行映射。 Last night when I was collecting tweets ,there was a coordinates field in the Json object returned by streaming api , Today i am trying to do the same thing just to filter tweets further that only those tweets be selected where coordinates is not null. 昨天晚上,当我收集推文时,流api返回的Json对象中有一个坐标字段。今天,我试图做同样的事情,只是进一步过滤推文,以便仅选择坐标不为null的那些推文。 But every Json object i am getting does not have a coordinates field. 但是我得到的每个Json对象都没有一个坐标字段。 I have searched google and Twitter Api documentation but to no avail. 我已经搜索过Google和Twitter Api文档,但无济于事。 What is the issue and how can i approach this? 问题是什么,我该如何解决?

Code: 码:

if (json_object["user"]["geo_enabled"]==True):
    print json_object["user"]["coordinates"]  #This doesn't print anything 

The coordinates field is not populated by default because of privacy reasons. 由于隐私原因,默认情况下不填充coordinates字段。 The user has to specifically turn on this geolocation feature in their profile. 用户必须在其个人资料中专门打开此地理位置功能。 The reason why you are not seeing it used is because very few people enable it -- fewer than 1% of tweets. 之所以没有看到它的使用,是因为很少有人启用它-不到1%的推文。 The place field is more often used. place字段更常用。 However, it will not give you a point location. 但是,它不会给您点位置。 It has a place name and a bounding box. 它具有一个地名和一个边界框。

to retrieve coordinate or place (if coordinates are None), of all tweets with word love, I use: 为了检索所有带有“ love”一词的推文中的坐标或位置(如果坐标为“无”),我使用:

for tweet in tweepy.Cursor(api.search, q='love', count = 10).items():
    if (tweet.coordinates is not None):
        lon = tweet.coordinates['coordinates'][0]
        lat = tweet.coordinates['coordinates'][1]
     elif (tweet.place  is not None):
         # counding box of location
         bbox = tweet.place.bounding_box.coordinates
         lon = bbox[0][0][0]
         lat = bbox[0][0][1]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM