From 1524b94b1ee3857fc03bbd459b618961aa5d7764 Mon Sep 17 00:00:00 2001 From: LVKinyanjui Date: Thu, 15 Aug 2024 16:19:40 +0300 Subject: [PATCH] Fixed the getting oauth pin issue on authorization --- User-Lookup/get_users_me_user_context.py | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/User-Lookup/get_users_me_user_context.py b/User-Lookup/get_users_me_user_context.py index f4a3bd4..27ceb21 100644 --- a/User-Lookup/get_users_me_user_context.py +++ b/User-Lookup/get_users_me_user_context.py @@ -6,8 +6,8 @@ # export 'CONSUMER_KEY'='' # export 'CONSUMER_SECRET'='' -consumer_key = os.environ.get("CONSUMER_KEY") -consumer_secret = os.environ.get("CONSUMER_SECRET") +consumer_key = os.environ.get("TWITTER_API_KEY") +consumer_secret = os.environ.get("TWITTER_API_KEY_SECRET") # User fields are adjustable, options include: # created_at, description, entities, id, location, name, @@ -16,25 +16,25 @@ fields = "created_at,description" params = {"user.fields": fields} + +if consumer_key is None or consumer_secret is None: + print("Consumer key or consumer secret is missing.") + + +# If credentials file doesn't exist, proceed with authentication # Get request token -request_token_url = "https://api.twitter.com/oauth/request_token" +request_token_url = "https://api.twitter.com/oauth/request_token?oauth_callback=oob&x_auth_access_type=write" oauth = OAuth1Session(consumer_key, client_secret=consumer_secret) - -try: - fetch_response = oauth.fetch_request_token(request_token_url) -except ValueError: - print( - "There may have been an issue with the consumer_key or consumer_secret you entered." - ) +fetch_response = oauth.fetch_request_token(request_token_url) resource_owner_key = fetch_response.get("oauth_token") resource_owner_secret = fetch_response.get("oauth_token_secret") -print("Got OAuth token: %s" % resource_owner_key) -# # Get authorization +# Get authorization base_authorization_url = "https://api.twitter.com/oauth/authorize" authorization_url = oauth.authorization_url(base_authorization_url) -print("Please go here and authorize: %s" % authorization_url) + +print("Please go here and authorize:", authorization_url) verifier = input("Paste the PIN here: ") # Get the access token