Reputation: 23
I am extremely new to Python and Twitter development, so I am completely lost. I am just trying to tweet using Python and tweepy for a project that I am doing. But I cannot authenticate my credentials. This is super irritating. Any help would be helpful! I am using Python 2.7 and this is my code:
import tweepy
consumer_key = '*************'
consumer_secret = '*********************'
access_token = '****************'
access_token_secret = '************************'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
api.update_status('Hello from tweepy!')
and then I get this in return:
Traceback (most recent call last):
File "<pyshell#27>", line 2, in
api.update_status('Hello from tweepy!')
File "build/bdist.macosx-10.9-intel/egg/tweepy/binder.py", line 230, in_call
return method.execute()
File "build/bdist.macosx-10.9-intel/egg/tweepy/binder.py", line 203, in execute
raise TweepError(error_msg, resp)
TweepError: [{u'message': u'Your credentials do not allow access to this resource.', u'code':220}]
Upvotes: 2
Views: 3125
Reputation: 790
I ran into the same authentication problem "Could not authenticate you" with my first attempt to connect via tweepy library. Even though I had just created the Twitter Consumer Keys and Access Tokens, I was able to resolve this by regenerating both sets and putting the new keys into my Python program.
Upvotes: 1
Reputation: 1476
I think the problem is with the access grant. You have to add your mobile number for your application to get write access like "status update". If you have not done that, just go to your applications via twitter developer account. Click on your application name. In your application page you will find a Permissions tab. Click there and then select "Read, Write and Direct messages" radio button and click Update settings.
You will be shown an error like below.
Error You must add your mobile phone to your Twitter profile before granting your application write capabilities. Please read https://support.twitter.com/articles/110250-adding-your-mobile-number-to-your-account-via-web for more information`
go to the link and add your mobile number according to the instructions. If it is not allowed for your country mobile service provider yet; I am sorry to say you have only read permission. You cannot write, direct msgs to your twitter via apps.
For more info on this, please feel free to visit my blog link http://candpy-progs.blogspot.in/2012/12/chapter3-of-head-first-programming.html
Upvotes: 0
Reputation: 3186
The problem is that you need to authorize your app to use your account. This may seem strange since you developed the app, but OAuth was originally designed to be used by many people rather than just the developer. On Pastebin I have uploaded the short authorize script that I used to authenticate my Tumblr App. Just switch out the urls and your keys before you run the app. Also, it uses OAuth2, but you are free to use tweepy once you have given access to your app.
Upvotes: 2