I am using the code below to publish Tweet. This is a fairly standard authentication procedure, but for some reason I cannot authenticate. The error I get is thisTwitter API returned a 401 (Unauthorized), Invalid or expired token.
from twython import Twython, TwythonError
import requests
APP_KEY = 'rpOzpgp2FZNJqsq0'
APP_SECRET = 'FKBJWXOJwXTblhi1xBl4PtKgPemNFvumH'
twitter = Twython(APP_KEY, APP_SECRET)
auth = twitter.get_authentication_tokens()
OAUTH_TOKEN = auth['oauth_token']
OAUTH_TOKEN_SECRET = auth['oauth_token_secret']
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
oauth_verifier_url = auth['auth_url']
oauth_verifier = requests.get(oauth_verifier_url)
final_step = twitter.get_authorized_tokens(oauth_verifier)
OAUTH_TOKEN = final_step['oauth_token']
OAUTH_TOKEN_SECRET = auth['oauth_token_secret']
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
twitter.update_status(status='Yo')
Here is the complete error message:
Traceback (most recent call last):
File "test.py", line 20, in <module>
final_step = twitter.get_authorized_tokens(oauth_verifier)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/twython/api.py", line 380, in get_authorized_tokens
ken'), error_code=response.status_code)
twython.exceptions.TwythonError: Twitter API returned a 401 (Unauthorized), Invalid / expired To ken
Why can I get this error and what can I fix it?
I tried to update my keys several times. I even uninstalled my application and created new ones several times, but I still keep getting this error.
In the "Application Settings" section, my access level is set to read and write:
Application Page Screenshot
I am not behind a firewall.
, Twython , , , , .