加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

如何在tweepy的流API中使用’count’参数?

发布时间:2020-12-20 11:20:14 所属栏目:Python 来源:网络整理
导读:当我在filter()调用中不包含count参数时,我可以正常使用流API,但是当我尝试指定我希望接收的历史记录中有多少推文时,我的流对象返回None. import tweepyfrom tweepy.streaming import StreamListener,Streamclass Listener (StreamListener): def on_status(
当我在filter()调用中不包含count参数时,我可以正常使用流API,但是当我尝试指定我希望接收的历史记录中有多少推文时,我的流对象返回None.

import tweepy
from tweepy.streaming import StreamListener,Stream

class Listener (StreamListener):
    def on_status(self,status):
        print '-' * 20
        print status.text
        return

def get_tweets(request):
    # if request.is_ajax():
    # All keys and secrets are declared here,but were removed for security reasons.

    auth = tweepy.OAuthHandler(CONSUMER_KEY,CONSUMER_SECRET)
    auth.set_access_token(ACCESS_KEY,ACCESS_SECRET)
    api = tweepy.API(auth)
    listener = Listener()
    stream = Stream(auth,listener)
    stream.filter(follow=("14739093",),count=-5)

我也尝试了以下内容,看看它返回了什么.

>>> something = stream.filter(follow=("14739093",count=-5)
>>> print something
None

谢谢你的帮助!

解决方法

Stream.filter总是返回None,它的工作就是将数据传递给StreamListener.

你的问题是Twitter只允许某些“角色”的count参数.

Firehose,Links,Birddog and Shadow clients interested in capturing all statuses should maintain a current estimate of the number of statuses received per second and note the time that the last status was received. Upon a reconnect,the client can then estimate the appropriate backlog to request. Note that the count parameter is not allowed elsewhere,including track,sample and on the default access role.

这是您尝试使用count参数时出现413错误的原因 – 您处于“默认访问”角色.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读