Reputation: 1
Why does the following error occur when I attempt to access the Twitter API?
AttributeError Traceback (most recent call last) in () 17 18 ---> 19 auth = twitter.oauth.OAuth(access_token_key,access_token_secret,consumer_key,consumer_secret) 20 #twitter = twitter.Twitter(auth=twitter.oauth.OAuth(access_token_key,access_token_secret,consumer_key,consumer_secret)) 21 twitter_api = twitter.Twitter(auth=auth)
AttributeError: 'module' object has no attribute 'oauth'
My code:
import twitter
#from twitter import *
#from twitter import oauth
consumer_key = ''
consumer_secret =''
access_token_key = ''
access_token_secret = ''
auth = twitter.oauth.OAuth(access_token_key,access_token_secret,consumer_key,consumer_secret)
#twitter = twitter.Twitter(auth=twitter.oauth.OAuth(access_token_key,access_token_secret,consumer_key,consumer_secret))
twitter_api = twitter.Twitter(auth=auth)
print twitter
Upvotes: 0
Views: 522
Reputation: 23
In addition to the above answer, also ensure that you have done -
pip install oauth
Upvotes: 0
Reputation: 15953
I would read their documentation carefully.
From the link I mentioned:
from twitter import *
t = Twitter(
auth=OAuth(token, token_key, con_secret, con_secret_key))
So you see that auth=OAuth
not auth=oauth.OAuth
In your case you have import twitter
, the only difference that's there is you'll need to add twitter
before each attribute as you have done, but you still don't need oauth
import twitter
t = twitter.Twitter(
auth=twitter.OAuth(token, token_key, con_secret, con_secret_key))
Upvotes: 0