Skip to content

Instantly share code, notes, and snippets.

@itsonlybarney
Created May 24, 2017 06:33
Show Gist options
  • Save itsonlybarney/91e8a25487f0d0e6a809b51f53e2effc to your computer and use it in GitHub Desktop.
Save itsonlybarney/91e8a25487f0d0e6a809b51f53e2effc to your computer and use it in GitHub Desktop.
Twitter OAuth Authentication
from tweepy import API, OAuthHandler, TweepError
from src.keys import CONSUMER_KEY, CONSUMER_SECRET
def auth():
''' Connect to Twitter '''
auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
try:
redirect_url = auth.get_authorization_url()
except TweepError:
print('Token Error')
print('Goto: ' + redirect_url)
verifier = input('Verifier code from Twitter.com: ')
try:
auth.get_access_token(verifier)
print("Access Token: " + auth.access_token)
print("Access Secret: " + auth.access_token_secret)
return auth
except TweepError:
print('Verification Error\n')
if __name__ == '__main__':
auth = auth()
api = API(auth)
api.update_status('A Tweet from Python!')
'''
Twitter API Keys
@username
'''
CONSUMER_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxx'
CONSUMER_SECRET = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment