Twitter流按位置过滤

时间:2011-08-29 04:44:50

标签: filter twitter location twitter-streaming-api

Twitter Stream API是否可以按位置字段过滤推文?正如您在下面的示例JSON条目中看到的那样,有“location”:“philippines”字段 - 值。现在,我想要的是通过位置字段过滤来自该位置的推文。但是不要误会我的意思。我不是在谈论GEO标签过滤器。

这可能吗?

{"geo":null,"in_reply_to_screen_name":null,"truncated":false,"text":"RT @BreakingNewsPH: Typhoon hits Taiwan after pummeling Philippines: Typhoon Nanmadol slammed into\u2026 http:\/\/t.co\/rF3jbVU #breakingnews","in_reply_to_user_id_str":null,"contributors":null,"retweeted":false,"retweet_count":1,"entities":{"hashtags":[{"text":"breakingnews","indices":[120,133]}],"urls":[{"indices":[100,119],"display_url":"goo.gl\/fb\/JVdpj","expanded_url":"http:\/\/goo.gl\/fb\/JVdpj","url":"http:\/\/t.co\/rF3jbVU"}],"user_mentions":[{"indices":[3,18],"name":"Breaking News PH","screen_name":"BreakingNewsPH","id":190144401,"id_str":"190144401"}]},"coordinates":null,"retweeted_status":{"geo":null,"in_reply_to_screen_name":null,"truncated":false,"text":"Typhoon hits Taiwan after pummeling Philippines: Typhoon Nanmadol slammed into\u2026 http:\/\/t.co\/rF3jbVU #breakingnews","in_reply_to_user_id_str":null,"contributors":null,"retweeted":false,"retweet_count":1,"entities":{"hashtags":[{"text":"breakingnews","indices":[100,113]}],"urls":[{"indices":[80,99],"display_url":"goo.gl\/fb\/JVdpj","expanded_url":"http:\/\/goo.gl\/fb\/JVdpj","url":"http:\/\/t.co\/rF3jbVU"}],"user_mentions":[]},"coordinates":null,"place":null,"source":"\u003Ca href=\"http:\/\/www.google.com\/support\/youtube\/bin\/answer.py?hl=en&answer=164577\" rel=\"nofollow\"\u003EGoogle\u003C\/a\u003E","created_at":"Mon Aug 29 04:16:31 +0000 2011","in_reply_to_user_id":null,"user":{"listed_count":19,"favourites_count":0,"profile_sidebar_fill_color":"252429","location":"Philippines","profile_background_tile":false,"lang":"en","profile_link_color":"2FC2EF","description":"Follow us to receive round-the-clock Philippine Breaking News updates directly on your Twitter account!","default_profile_image":false,"default_profile":false,"verified":false,"profile_sidebar_border_color":"181A1E","notifications":null,"time_zone":"Hong Kong","created_at":"Mon Sep 13 05:14:02 +0000 2010","followers_count":804,"following":null,"profile_use_background_image":true,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/images\/themes\/theme9\/bg.gif","profile_image_url":"http:\/\/a3.twimg.com\/profile_images\/1130204413\/breakingnewsph-logo-small_normal.png","show_all_inline_media":false,"follow_request_sent":null,"geo_enabled":false,"profile_background_color":"1A1B1F","protected":false,"contributors_enabled":false,"profile_background_image_url":"http:\/\/a1.twimg.com\/images\/themes\/theme9\/bg.gif","url":"http:\/\/www.breakingnews.ph","screen_name":"BreakingNewsPH","name":"Breaking News PH","friends_count":210,"profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1130204413\/breakingnewsph-logo-small_normal.png","id":190144401,"id_str":"190144401","is_translator":false,"statuses_count":51981,"utc_offset":28800,"profile_text_color":"666666"},"in_reply_to_status_id":null,"favorited":false,"id":108030240370073602,"possibly_sensitive":false,"in_reply_to_status_id_str":null,"id_str":"108030240370073602"},"place":null,"source":"web","created_at":"Mon Aug 29 04:23:44 +0000 2011","in_reply_to_user_id":null,"user":{"listed_count":0,"favourites_count":1,"profile_sidebar_fill_color":"FFF7CC","location":"cabuyao,Laguna PHILIPINES","profile_background_tile":false,"lang":"en","profile_link_color":"FF0000","description":"Prudence keeps life safe, but it does not often make it happy.","default_profile_image":false,"default_profile":false,"verified":false,"profile_sidebar_border_color":"F2E195","notifications":null,"time_zone":"Alaska","created_at":"Sun Nov 14 09:15:11 +0000 2010","followers_count":32,"following":null,"profile_use_background_image":true,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/188170056\/Picture_276.jpg","profile_image_url":"http:\/\/a2.twimg.com\/profile_images\/1423110432\/271010_220561634650699_100000905924979_647505_1229915_n_normal.jpg","show_all_inline_media":true,"follow_request_sent":null,"geo_enabled":false,"profile_background_color":"BADFCD","protected":false,"contributors_enabled":false,"profile_background_image_url":"http:\/\/a1.twimg.com\/profile_background_images\/188170056\/Picture_276.jpg","url":null,"screen_name":"emerlyn14","name":"Emerlyn Cantalejo","friends_count":215,"profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1423110432\/271010_220561634650699_100000905924979_647505_1229915_n_normal.jpg","id":215568114,"id_str":"215568114","is_translator":false,"statuses_count":270,"utc_offset":-32400,"profile_text_color":"0C3E53"},"in_reply_to_status_id":null,"favorited":false,"id":108032058986729472,"possibly_sensitive":false,"in_reply_to_status_id_str":null,"id_str":"108032058986729472"}

2 个答案:

答案 0 :(得分:8)

检查https://dev.twitter.com/docs/streaming-api/methods#locations

上的twitter流API
  

<强>地点

     

指定要跟踪的一组边界框。只有两个推文   使用地理标记API创建并从跟踪中放置   边界框将包含在流中 - 用户的位置   字段不用于过滤推文(例如,如果用户具有其位置   设置为“旧金山”,但推文不是使用   地理标记API并没有地理元素,它不会被包含在内   流)。边界框被指定为逗号单独的列表   经度/纬度对,第一对表示西南   盒子的一角。例如,locations = -122.75,36.8,-121.75,37.8   将追踪旧金山地区的推文。多重边界   可以通过连接纬度/经度对来指定框   示例:locations = -122.75,36.8,-121.75,37.8,-74,40,-73,41将跟踪   来自旧金山和纽约市的推文。

     

与track参数一样,查询受Track影响   限制,在跟踪限制和受访问角色中描述,   在状态/过滤方法中描述。数量和大小   边界框是有限的。边框可以达到360度   纬度为180度经度,最多可指定25个   边界框。一个360度到180度的盒子将覆盖   整个地球。更高的访问级别提供了额外的边界框。

     

边界框是逻辑OR。可以组合位置参数   有跟踪参数,但请注意所有术语在逻辑上都是ORd,所以   查询字符串   track = twitter&amp; amp; locations = -122.75,36.8,-121.75,37.8会匹配   任何包含Twitter(即使是非地理推文)或即将发布的推文   来自旧金山地区。

     

值:经度/纬度对,以逗号分隔。第一对   指定框的西南角。方法:状态/过滤器

     

示例:创建一个名为“locations”的文件,其中包含,排除   引号,短语:   “locations = -122.75,36.8,-121.75,37.8,-74,40,-73,41”然后执行:

curl -d @locations https://stream.twitter.com/1/statuses/filter.json
-uAnyTwitterUser:Password. 
     

您将收到来自旧金山和新的所有地理标记的推文   约克市区。

答案 1 :(得分:1)

嗯..你不能用twitter api..twitter不要过滤位置字段只有地理标记..如果你想要过滤器位置你必须编写一个过滤器来过滤该位置json respnse ..这真的很低效,你会失去很多twitts,因为你只有不到10%的公共身份:

状态/样品

返回所有公共状态的随机样本。默认访问级别“Spritzer”提供Firehose的一小部分,非常粗略地占所有公共状态的1%。 “Gardenhose”访问级别提供了更适合数据挖掘和研究应用的比例,这些应用需要更大比例的统计上显着的样本。目前,Gardenhose非常粗略地返回所有公共状态的10%。请注意,由于交通流量不同,这些比例可能会进行突击调整。

你也可以阅读:

状态/流水

返回所有公共状态。 Firehose不是一般可用的资源。很少有应用程序需要此级别的访问权限。创造性地使用其他资源和各种访问级别的组合几乎可以满足每个应用程序用例。

所以..你只有2个选项.1)使用位置过滤器过滤整个国家或2)只获得1%的完整公共状态并过滤它,也许读它可以帮助你:

再见和快乐的编码