2015-05-04 68 views
0

使用下面的代码,我试图得到一个哈希标签。它适用于像#StarWars这样的大型搜索,但是当我询问较小的搜索时,它似乎不会返回任何内容。Twitter流不适用于Tweepy

想法?

“代码”代替实际的字符串进行身份验证

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']) 

回答

0

好了,发现这个问题的答案是,我期待它的工作复古积极。这是我的一个基本错误。相反,实际发生的是目前的被推送。以前不是。