我正试图通过twitter API从twitter上收集推文。我在twitterStream语句中收到错误,如下所示:我如何解决它。
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
import time
ckey = 'serhsrtjhath'
csecret = 'sdfhszdjsrztj'
atoken = 'aerhyaetjsjk'
asecret = 'srtjsrkisk'
class StdOutListener(StreamListener):
def on_data(self, data):
try:
#print data
saveFile = open('tweetdb.csv', 'a')
saveFile.write(data)
saveFile.write('\n')
saveFile.close()
return True
except BaseException, e:
print 'failed ondata,',str(e)
time.sleep(5)
def on_error(self, status):
print status
l = StdOutListener()
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
twitterStream = Stream(auth, l)
twitterStream.filter(track=["Paris"])
错误:
Traceback (most recent call last):
File "scrape_data.py", line 34, in <module>
twitterStream = Stream(auth, l)
TypeError: __init__() takes at least 4 arguments (3 given)
注意:我使用Python 2.7。