Created
May 24, 2017 06:33
-
-
Save itsonlybarney/91e8a25487f0d0e6a809b51f53e2effc to your computer and use it in GitHub Desktop.
Twitter OAuth Authentication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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