farhawa
farhawa

Reputation: 10398

Python - how to get tweets in real time by hashtag

I am looking for a pythonic way to get a stream of tweets by hashtag. What I found so far is the tweepy package using this code:

from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener

class listener(StreamListener):

    def on_data(self, data):
        print(data)
        return(True)

    def on_error(self, status):
        print "error"
        print status

auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)

twitterStream = Stream(auth, listener())
twitterStream.filter(track=["#iPhone"])

The problem is that I don't understand how can I get the consumer_key, consumer_secret, access_token, access_secret arguments.

I am doing the right thing? Is this the best way to collect tweets by hashtag using python? If so, how to get the that 4 arguments?

Upvotes: 1

Views: 1330

Answers (0)

Related Questions