gpt4 book ai didi

python - 如何在 tweepy 的流 API 中使用 'count' 参数?

转载 作者:太空宇宙 更新时间:2023-11-03 13:23:09 27 4
gpt4 key购买 nike

当我不在 filter() 调用中包含 count 参数时,我可以很好地使用流式 API,但是当我尝试指定来 self 想要接收的历史记录,我的流对象返回 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 错误的原因——您处于“默认访问”角色。

关于python - 如何在 tweepy 的流 API 中使用 'count' 参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7111346/

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