Reputation: 1206
I am using the python V2.75 and have installed all the twitter related packages for python using the command 'pip install twitter'. I have played around it and the api works fine. Now, I want to access the streaming api of the twitter for real time tweets. I have written the code as shown below
import twitter
twitter_stream = twitter.TwitterStream(auth=UserPassAuth('username', 'password'))
res = twitter_stream.statuses.filter(track='obama')
When i try to run the above code it throws an error "NameError: name 'UserPassAuth' is not defined". I could figure out that some packages have not been imported/missing. Could u please suggest some ways to get it working.
Upvotes: 0
Views: 1104
Reputation: 48287
Read about namespaces. Class UserPassAuth is not defined in your global namespace, only
twitter package is. Use absolute reference, as twitter.UserPassAuth
:
twitter_stream = twitter.TwitterStream(auth=twitter.UserPassAuth('username', 'password'))
It seams that you are following http://people.fas.harvard.edu/~astorer/twitter/twitter.html. Probably a typo (I doubt they meant to import UserPassAuth
, since TwitterStream
is referenced from module)
Upvotes: 1