微博回复流中的tweet



我有一个twitter bot,它响应包含hashtag的tweet。我一直在使用twt = api.search(q='param')来拉推文,它一直在完美地工作,但我已经切换到myStreamListener = MyStreamListener() twt = tweepy.Stream(auth = api.auth, listener=myStreamListener())来实时拉推文。但这行不通,我不知道为什么。下面是我的代码:

myStreamListener = MyStreamListener()
twt = tweepy.Stream(auth = api.auth, listener=myStreamListener())
twt.filter(track=['#www'], async=True)
#list of specific strings we want to omit from responses
badWords = ['xxx','yyy' ]
#list of specific strings I want to check for in tweets and reply to
genericparam = ['@zzz']
def does_contain_words(tweet, wordsToCheck):
    for word in wordsToCheck:
        if word in tweet:
            return True
    return False
for currentTweet in twt:
    #if the tweet contains a good word and doesn't contain a bad word
    if does_contain_words(currentTweet.text, genericparam) and not does_contain_words(currentTweet.text, badWords):
        #reply to tweet
        screen = currentTweet.user.screen_name
        message = "@%s this is a reply" % (screen)
        currentTweet = api.update_status(message, currentTweet.id)

我相信你的问题是你试图通过流发送回复,而不是在单独的线程中使用http请求。不可能像下面解释的那样这样做:

https://dev.twitter.com/streaming/overview

偶然发现的

创建myStreamListener = MyStreamListener(self.api) self。你想要使用的api实例需要传递给StreamListner构造函数,否则它将为null。

最新更新