0
我正在嘗試使用Twitter API來傳輸包括密歇根州,斯巴達和MSU在內的所有推文。在我能弄明白這一點後,我想用不同的big10關鍵詞。然而,我運行這個代碼,我無法通過 ln(*),無論我等待多久都沒有發生。我的代碼有問題嗎?或者如何獲得這些信息的顯示,以便我可以分析它?試圖使用Twitter API,但我的代碼不會運行任何東西
謝謝!
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
#Variables that contains the user credentials to access Twitter API
access_token = "ENTER YOUR ACCESS TOKEN"
access_token_secret = "ENTER YOUR ACCESS TOKEN SECRET"
consumer_key = "ENTER YOUR API KEY"
consumer_secret = "ENTER YOUR API SECRET"
#This is a basic listener that just prints received tweets to stdout.
class StdOutListener(StreamListener):
def on_data(self, data):
print data
return True
def on_error(self, status):
print status
if __name__ == '__main__':
#This handles Twitter authentification and the connection to Twitter Streaming API
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, l)
#This line filter Twitter Streams to capture data by the keywords: 'MichiganState', 'Spartans', 'MSU'
stream.filter(track=['MichiganState', 'Spartans', 'MSU'])'