【问题标题】:Twitter Stream not working for TweepyTwitter Stream 不适用于 Tweepy
【发布时间】:2015-05-04 22:23:49
【问题描述】:

使用下面的代码,我正在尝试获取哈希标记。它适用于#StarWars 等较大的搜索,但当我要求较小的搜索时,它似乎没有返回任何内容。

想法?

使用'code'代替实际的字符串进行身份验证

from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
from textwrap import TextWrapper
import json

access_token = "code"
access_token_secret = "code"
consumer_key = "code"
consumer_secret = "code"

class StdOutListener(StreamListener):
    ''' Handles data received from the stream. '''

    status_wrapper = TextWrapper(width=60, initial_indent='    ', subsequent_indent='    ')

    def on_status(self, status):
        try:
            print self.status_wrapper.fill(status.text)
            print '\n %s  %s  via %s\n' % (status.author.screen_name, status.created_at, status.source)
        except:
            # Catch any unicode errors while printing to console
            # and just ignore them to avoid breaking application.
            pass

    def on_error(self, status_code):
        print('Got an error with status code: ' + str(status_code))
        return True # To continue listening

    def on_timeout(self):
        print('Timeout...')
        return True # To continue listening

if __name__ == '__main__':
    listener = StdOutListener()
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)

    stream = Stream(auth, listener)
    stream.filter(track=['#TestingPythonTweet'])

【问题讨论】:

    标签: python twitter tweepy


    【解决方案1】:

    好的,所以发现这个问题的答案是我希望它可以追溯工作。这是我的一个根本错误。相反,实际发生的是它获取了 当前 正在发布的内容。以前不是。

    【讨论】:

      猜你喜欢
      • 2016-02-08
      • 2011-12-27
      • 1970-01-01
      • 2012-10-09
      • 2013-06-15
      • 1970-01-01
      • 2019-10-02
      • 2013-09-17
      • 2014-01-30
      相关资源
      最近更新 更多