使用Tweepy从Twitter进行实时流推文。但是没有过滤器

时间:2019-09-30 14:37:42

标签: twitter tweepy

嗨,我正在尝试使用tweepy来传输来自Twitter的实时tweet。我有以下代码,但我想删除过滤器属性。无论过滤器如何,我都想获取该推文。我该怎么办?


from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
import time 
import sys

ckey = '<consumer key>'
csecret = '<consumer secret>'
atoken = '<access token>'
asecret = '<access token secret>'

class listener(StreamListener):

    def on_data(self,data):
        try:
            saveFile = open('twitDB.csv','a')
            saveFile.write(data)
            saveFile.close()
            return True
        except BaseException,e:
            print ('failed ondata, ',str(e))
            time.sleep(5)

    def on_error(self,status):
        print (status)

auth = OAuthHandler(ckey,csecret)
auth.set_access_token(ato]ken,asecret)
twitterStream = Stream(auth,listener())
twitterStream.filter(track=["car"])

1 个答案:

答案 0 :(得分:0)

As Andy Piper said,您可以使用 Stream.sample 使用 GET statuses/sample endpoint