开发者

How to use the 'count' parameter in tweepy's streaming API?

I can use the streaming API just fine when I don't include t开发者_C百科he count parameter in filter() call, but when I try to specify how many tweets from my history I want to receive, my stream object returns 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)

I also tried the following, to see what it was returning.

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

Thanks for your help!


Stream.filter always returns None, its job is just to pass the data on to the StreamListener.

Your problem is that Twitter only allows the count parameter for certain "roles".

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.

This is the reason you're getting a 413 error when you try to use the count parameter -- you're on the "default access" role.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜