gog*_*urt 8 python twitter tweepy
我试图简单地连接到Twitter streaming APIusing tweepy(和python 3),并从给定的单个用户流式传输所有推文.
我觉得这是可能的,所以我有以下简单的代码来做到这一点:
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'])
Run Code Online (Sandbox Code Playgroud)
当我从命令行运行它时,我只是从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",
[...]
Run Code Online (Sandbox Code Playgroud)
该Tweepy 3.3.0更新日志中提到的几个流的改善,虽然我没有看到他们提"冻结"的问题.
| 归档时间: |
|
| 查看次数: |
6693 次 |
| 最近记录: |