3

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

这可能吗?

{"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"}
4

2 回答 2

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,

与 track 参数一样,查询受 Track 限制(在 Track Limiting 中描述)和访问角色(在 statuses/filter 方法中描述)的约束。边界框的数量和大小都是有限的。边界框最多可以是经度 360 度乘纬度 180 度,您最多可以指定 25 个边界框。一个 360 度乘 180 度的盒子将覆盖整个地球。更高的访问级别提供额外的边界框。

边界框是逻辑 OR。位置参数可以与跟踪参数组合,但请注意,所有术语都是逻辑 ORd,因此查询字符串 track=twitter&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. 

您将收到来自旧金山和纽约市地区的所有带有地理标签的推文。

于 2011-11-04T04:12:29.647 回答
1

好吧..你不能用twitter api来做到这一点..twitter不要只过滤位置字段geotag..如果你想要过滤位置,你必须编写一个过滤器来过滤json响应中的位置..它真的效率低下,你会失去很多 twitts,因为你只获得了更少的 10% 的公共状态:

状态/样本

返回所有公共状态的随机样本。默认访问级别“Spritzer”提供了 Firehose 的一小部分,非常粗略地说,占所有公共状态的 1%。“Gardenhose”访问级别提供了更适合数据挖掘和研究应用程序的比例,这些应用程序希望更大比例成为具有统计意义的样本。目前,Gardenhose 非常粗略地返回了所有公共状态的 10%。请注意,随着流量的变化,这些比例可能会不经宣布进行调整。

你也可以阅读:

状态/消防水带

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

所以..您只有 2 个选项..1) 使用位置过滤器过滤您的整个国家或 2) 仅接收 1% 的整个公共状态并对其进行过滤,也许阅读它可以帮助您:

再见,快乐编码

于 2011-12-17T03:05:30.460 回答