Reputation: 2039
I am trying to use the twitter library to pull some tweets but I am unable to get my authorization correctly. This is my code
import twitter
consumer_key = ''
consumer_secret = ''
access_token = ''
access_secret = ''
t = Twitter( auth = OAuth(access_token, access_secret, consumer_key, consumer_secret))
api = twitter.Twitter( auth = auth )
print api
It is throwing AttributeError:'module' object has no attribute 'oauth'. I am simply pasting code from twitter help but then why is it not working?
Upvotes: 1
Views: 2535
Reputation: 2039
As I am using import twitter I need to suffix twitter in front of any classname or any function of any class belonging to module twitter. This is the correct code:
import twitter
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
t = twitter.Twitter( auth = twitter.oauth.OAuth(access_token, access_token_secret, consumer_key, consumer_secret))
print t
Upvotes: 0
Reputation: 4583
Without knowing which library you are using I'm going to assume you are using this one because the syntax looks the same. The error being thrown suggests that you are not importing the module that handles oauth. You could import all modules by adding this to the top of your code:
from twitter import *
This isn't really recommended because you might not need every module in the library so just import the ones you need e.g.:
from twitter import oauth
Upvotes: 1