changed streaming.py to oauth from basic auth
authorJose Asuncion <jose.asuncion@gmail.com>
Tue, 10 Jul 2012 11:44:57 +0000 (19:44 +0800)
committerJose Asuncion <jose.asuncion@gmail.com>
Tue, 10 Jul 2012 11:44:57 +0000 (19:44 +0800)
examples/streaming.py

index 34f614842123e66ed92343360e60a8a3c8047d83..ece230c9f87a5658c0e187a20959615a68c75211 100644 (file)
@@ -1,11 +1,22 @@
 from tweepy.streaming import StreamListener
-from tweepy.auth import BasicAuthHandler
+from tweepy import OAuthHandler
 from tweepy import Stream
 
-TWITTER_USERNAME = ''
-TWITTER_PASSWORD = ''
+# Go to http://dev.twitter.com and create an app. 
+# The consumer key and secret will be generated for you after
+consumer_key=""
+consumer_secret=""
+
+# After the step above, you will be redirected to your app's page.
+# Create an access token under the the "Your access token" section
+access_token=""
+access_token_secret=""
 
 class StdOutListener(StreamListener):
+       """ A listener handles tweets are the received from the stream. 
+       This is a basic listener that just prints received tweets to stdout.
+
+       """
        def on_data(self, data):
                print data
                return True
@@ -15,5 +26,8 @@ class StdOutListener(StreamListener):
 
 if __name__ == '__main__':
        l = StdOutListener()
-       stream = Stream(BasicAuthHandler(TWITTER_USERNAME, TWITTER_PASSWORD), l)
+       auth = OAuthHandler(consumer_key, consumer_secret)
+       auth.set_access_token(access_token, access_token_secret)
+
+       stream = Stream(auth, l)        
        stream.filter(track=['basketball'])