2010-11-07 121 views
1
stream.filter(locations=[-122.75,36.8,-121.75,37.8,-74,40,-73,41],track=["twitpic"]) 

This Works。但是,这不是“与”。这是“或”。该行获取位置OR关键字。 如何制作“AND”?如何使用Twitter流媒体API?

这里的代码库我使用:

def filter(self, follow=None, track=None, async=False, locations=None): 
     self.parameters = {} 
     self.headers['Content-type'] = "application/x-www-form-urlencoded" 
     if self.running: 
      raise TweepError('Stream object already connected!') 
     self.url = '/%i/statuses/filter.json?delimited=length' % STREAM_VERSION 
     if follow: 
      self.parameters['follow'] = ','.join(map(str, follow)) 
     if track: 
      self.parameters['track'] = ','.join(map(str, track)) 
     if locations and len(locations) > 0: 
      assert len(locations) % 4 == 0 
      self.parameters['locations'] = ','.join(['%.2f' % l for l in locations]) 
     self.body = urllib.urlencode(self.parameters) 
     self.parameters['delimited'] = 'length' 
     self._start(async) 

https://github.com/joshthecoder/tweepy/blob/master/tweepy/streaming.py

回答

2

http://dev.twitter.com/pages/streaming_api_methods#locations

边框进行逻辑OR值。甲 位置参数可被组合 与轨道参数,但请注意, 所有术语逻辑ORD,所以 查询字符串 轨道=叽叽喳喳&位置= -122.75,36.8,-121.75,37.8 将匹配包含任何鸣叫 来自旧金山地区的术语Twitter(即使是非地理推文)或 。

...

多个包围盒可以通过级联 纬度/经度对,例如指定 : 位置= -122.75,36.8,-121.75,37.8,-74,40 ,-73,41将跟踪来自旧金山 和纽约市的推文。

欲了解更多信息,请阅读完整的文档。