[英]Tweepy streaming API: filtering on user
我正在嘗試使用tweepy
(和python 3)簡單地連接到Twitter streaming API
,並從給定的單個用戶流式傳輸所有推文。
我覺得這是可能的,所以我有以下簡單的代碼來做到這一點:
from tweepy import StreamListener
from tweepy import Stream
import tweepy
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
class StdOutListener(StreamListener):
def on_data(self, data):
# process stream data here
print(data)
def on_error(self, status):
print(status)
if __name__ == '__main__':
listener = StdOutListener()
twitterStream = Stream(auth, listener)
twitterStream.filter(follow=['575930104'])
當我從命令行運行它時,我只是從Twitter獲得了一堆406代碼。 我試圖使用tweepy的方式有什么明顯的錯誤,或者“跟隨”參數是不是設計用於我認為它做的事情?
編輯:我也發布了這個討論板,僅供參考。
我能夠使用Tweepy 3.2.0在Python 3.4上重現您的問題。 升級到3.3.0解決了這個問題:
$ bin/pip install -U tweepy==3.2.0
[...]
Successfully installed tweepy requests-oauthlib six requests
Cleaning up...
$ bin/python test.py
406
^CTraceback (most recent call last):
[...]
KeyboardInterrupt
$ bin/pip install -U tweepy==3.3.0
[...]
Successfully installed tweepy requests requests-oauthlib six
Cleaning up...
$ bin/python test.py
{"created_at":"Fri Feb 27 14:02:02 +0000 2015","id":571309283217768448,"id_str":"571309283217768448",
[...]
Tweepy 3.3.0 Changelog提到了幾個流媒體改進,雖然我沒有看到他們提到的“凍結”問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.