简体   繁体   中英

Can not connect to Twitter using Tweepy Streaming

Trying to check whether connection established or not, but nothing happened

I used on_connect to understand but got nothing:

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()

You only created a Stream, you didn't start it, see the docs .

In this example we will use filter to stream all tweets containing the word python. The track parameter is an array of search terms to stream.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM