【问题标题】:Can not connect to Twitter using Tweepy Streaming无法使用 Tweepy Streaming 连接到 Twitter
【发布时间】:2016-01-22 23:50:48
【问题描述】:

尝试检查连接是否建立,但没有任何反应

我用on_connect理解却一无所获:

import tweepy
import time

class InOutStreamListener(tweepy.StreamListener):
    def on_connect(self):
        print 'Connected'    

    def disconnect(self):
        if self.running is False:
            return
        self.running = False

    def on_friends(self, friends):
        print friends[0]

auth = tweepy.OAuthHandler('code', 'code')
auth.set_access_token('code', 'code')

l = InOutStreamListener()    
streamer = tweepy.Stream(auth, l)

time.sleep(15)    
streamer.disconnect()

【问题讨论】:

    标签: python api twitter tweepy twitter-streaming-api


    【解决方案1】:

    您只是创建了一个 Stream,并没有启动它,请参阅 docs

    在这个例子中,我们将使用过滤器来流式传输所有包含 字蟒。 track 参数是一个搜索词数组 流。

    myStream.filter(track=['python'])

    【讨论】:

    • 它对我有用。我使用 streamer.filter(follow=['5345']) 进行监控。我只是想知道如何监控私信
    猜你喜欢
    • 2012-06-13
    • 1970-01-01
    • 1970-01-01
    • 2016-09-12
    • 1970-01-01
    • 2016-07-19
    • 1970-01-01
    • 2020-12-01
    • 2017-02-07
    相关资源
    最近更新 更多