gpt4 book ai didi

python - 如何使用 Twitter 流 API?

转载 作者:可可西里 更新时间:2023-11-01 17:15:21 24 4
gpt4 key购买 nike

stream.filter(locations=[-122.75,36.8,-121.75,37.8,-74,40,-73,41],track=["twitpic"])

这行得通。但是,它不是“和”。这是“或”。此行获取位置或关键字。如何使其成为“AND”?

这是我正在使用的库的代码:

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

最佳答案

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

Bounding boxes are logical ORs. A locations parameter may be combined with track parameters, but note that all terms are logically ORd, so the query string track=twitter&locations=-122.75,36.8,-121.75,37.8 would match any tweets containing the term Twitter (even non-geo tweets) OR coming from the San Francisco area.

...

Multiple bounding boxes may be specified by concatenating latitude/longitude pairs, for example: locations=-122.75,36.8,-121.75,37.8,-74,40,-73,41 would track tweets from San Francisco and New York City.

有关更多信息,请阅读完整文档。

关于python - 如何使用 Twitter 流 API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4116799/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com