Skip to content

Commit

Permalink
Fixed the getting oauth pin issue on authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
LVKinyanjui committed Aug 15, 2024
1 parent 8c63446 commit 1524b94
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions User-Lookup/get_users_me_user_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
# export 'CONSUMER_KEY'='<your_consumer_key>'
# export 'CONSUMER_SECRET'='<your_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,
Expand All @@ -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
Expand Down

0 comments on commit 1524b94

Please sign in to comment.