我正在尝试使用python中的tweepy
库从twitter-streaming-api中获取流数据。但是,即使经过大量试验,我也无法获得任何data
或按照on_data
方法进行打印。它给出了420错误消息。我怎么能避免呢?
import io
import json
import time
import tweepy
access_token = 'XXXXXX'
access_token_secret = 'XXXXXX'
consumer_key = 'XXXXXX'
consumer_secret = 'XXXXXX'
class MyListener(tweepy.StreamListener):
def on_status(self, status):
print(status.text)
def on_data(self, tweetdata):
data = json.loads(tweetdata)
print(data)
def on_error(self, status):
print(status)
auth = tweepy.OAuthHandler(consumer_secret=consumer_secret,consumer_key=consumer_key)
auth.set_access_token(access_token,access_token_secret)
api = tweepy.API(auth)
myListener = MyListener()
myStream = tweepy.Stream(auth = api.auth, listener=myListener)
myStream.filter(languages='en',track=['@NBA'],async=True)
myStream.disconnect()