Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Twitter Streaming API sample using the filter stream
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from tweepy.streaming import StreamListener, Stream
from tweepy.auth import BasicAuthHandler
from tweepy.api import API
import tweepy
class MyStreamListener(StreamListener):
def __init__(self, api=None):
StreamListener.__init__(self, api=api)
def on_status(self, status):
print "@%s: %s" % (status.user.screen_name, status.text)
def on_error(self, status_code):
print "ERROR: ",status_code
def on_limit(self, track):
print "LIMIT: ", track
def on_timeout(self):
print "TIMEOUT!"
def filter_track():
stream_auth = BasicAuthHandler('<USERNAME>', '<PASSWORD>')
api = API()
stream = Stream(stream_auth, MyStreamListener(api))
print 'start filter track ', ','.join(track)
if __name__ == "__main__":

This comment has been minimized.

Copy link

@tepietrondi tepietrondi commented Apr 28, 2012

good reference, i was trying to pass the oauth rather than the basic auth, thanks


This comment has been minimized.

Copy link

@billstar billstar commented Jul 20, 2012

Twitter's streaming API concepts doc says: "Basic Auth will eventually be deprecated on the Streaming API, but we have not planned or announced a timetable for this transition." I hope that AppEngine gets their http connection stuff straightened out before then.


This comment has been minimized.

Copy link
Owner Author

@mtrovo mtrovo commented Jul 20, 2012

@bstrathearn i saw this too, actually when I created this gist they already had this warning. I hope they don't deprecate it so soon, the last time I checked tweepy it still didn't support Streaming API login with OAuth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment