我試圖使用Tweepy python api創建一個twitter搜索流,但我面臨一個錯誤。這是我想執行的代碼,我得到的錯誤 -Tweepy Stream error:__init __()需要剛好3個參數(給出4個參數)
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
# Twitter Credentials
access_token_key = "*****"
access_token_secret = "*****"
consumer_key = "*****"
consumer_secret = "*****"
class StdOutListener(StreamListener):
""" A listener handles tweets that are the received from the stream.
This is a basic listener that just prints received tweets to stdout.
"""
def on_data(self, data):
print data
return True
def on_error(self, status):
print status
if __name__ == '__main__':
x = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token_key, access_token_secret)
stream = Stream(auth, x, "microsoft")
response = stream.filter(track=['microsoft'])
print response
你確定錯誤給你提供的方式,'_init_',而不是'__init__'? – alko
它是雙下劃線....我懶得打字。抱歉! – dsauce
@PreritAhuja:不要輸入錯誤信息;複製並粘貼它。 –