2015-05-04 108 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

好了,發現這個問題的答案是,我期待它的工作復古積極。這是我的一個基本錯誤。相反,實際發生的是目前的被推送。以前不是。