2011-08-29 277 views
2

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

这可能吗?

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

回答

1

好吧..你不能用twitter api来做它..twitter不要过滤位置字段只有geotag ..如果你想过滤器的位置,你必须编写一个过滤器来过滤json中的位置respnse..it真的效率低下,你会失去很多twitts因为你只收到10%以下公开状态:

状态/样品

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

,你可以阅读过:

状态/流水

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

so..you仅有2 options..1)使用位置过滤器过滤整个国家或2)只接收1%整个公共状态和过滤它,也许读它可以帮助你:

再见快乐编码

8

检查Twitter的流API在https://dev.twitter.com/docs/streaming-api/methods#locations

位置

指定一组边界框追踪。只有那些既 使用地理标记API创建和跟踪 边框内放置鸣叫将被包括在流中 - 用户的位置 字段不是用来过滤鸣叫(例如,如果一个用户都有自己的位置 设为“旧金山”,但推文不是使用地理标记API创建的,并且没有地理元素,因此不会包含在 流中)。边界框被指定为经度/纬度对的逗号分隔列表,第一对表示框的角落西南部 。例如,位置= -122.75,36.8,-121.75,37.8, 会跟踪来自旧金山地区的推文。例如:位置= -122.75,36.8,-121.75,37.8,-74,40,-73,41会追踪 来自旧金山和纽约市的推文。

与轨道参数一样,查询受轨迹 限制(在轨道限制中进行了描述并受到状态/过滤器方法中所述的访问角色 的限制)。 包围盒的数量和尺寸都是有限的。边界框可以高达360度,经度为纬度180度,并且您可以指定多达25个边界框 。一个360度180度的盒子将覆盖整个地球。较高的访问级别提供了额外的边界框。

边界框是逻辑或。 位置参数可以与轨道参数相结合,但是请注意,所有项都是逻辑ORd,因此 查询字符串 track = twitter & amp; locations = -122.75,36.8,-121.75,37.8将匹配 任何包含短期Twitter(甚至非地理推特)或来自旧金山地区的 。

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

示例:创建一个名为 '位置' 包含,但不包括 引号,短语的文件: “位置= -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. 

,您会收到所有的地理标记从旧金山和新 纽约地区的鸣叫。