Python中的Twitter API

时间:2017-07-24 16:55:08

标签: python api twitter

我正在尝试通过Python访问Twitter API并将推文导出到csv中,但似乎只是继续加载。我没有错误,但我只是想确保代码正常工作:

from tweepy import OAuthHandler
from tweepy import Stream
from tweepy.streaming import StreamListener
access_token=''
access_secret=''
consumer_key=''
consumer_secret=''
class listener(StreamListener):
def on_data(self,data):
    try:
        print(data)
        with open('TwitterAPI.csv','a')as f:
            f.write(data)
    except Exception as e: 
        print('[!]Error: %s' %e)
        return(True)
    def on_error(self,status):
        print(status)
auth=OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(access_token,access_secret)
twitterStream=Stream(auth,listener())
twitterStream.filter(track=["pythontweets"])

0 个答案:

没有答案