The request token is temporary and used only for the authorization step.
3
Generate Authorization URL
Direct the user to the authorization URL:
# Standard authorization flowauth_url = auth.get_authorization_url()# Or use "Sign in with X" flowauth_url = auth.get_authorization_url(login_with_x=True)print(f"Visit this URL to authorize: {auth_url}")
The user will be redirected to your callback URL with an oauth_verifier parameter.
from xdk import Client, OAuth1auth = OAuth1( api_key="your_api_key", api_secret="your_api_secret", callback="https://yourapp.com/callback", access_token="your_access_token", access_token_secret="your_access_token_secret")client = Client(auth=auth)# Now you can make authenticated requestsuser = client.users.get_me()print(f"Authenticated as: {user.data.username}")
For desktop applications without a web server, use the PIN-based flow:
auth = OAuth1( api_key="your_api_key", api_secret="your_api_secret", callback="oob" # "oob" enables PIN-based flow)# Start the flowauth_url = auth.start_oauth_flow()print(f"Visit this URL and authorize: {auth_url}")# User gets a PIN code after authorizationpin = input("Enter the PIN: ")access_token = auth.get_access_token(pin)
try: request_token = auth.get_request_token()except ValueError as e: print(f"Failed to get request token: {e}")try: access_token = auth.get_access_token(verifier)except ValueError as e: if "request token not obtained" in str(e): print("Call get_request_token() first") else: print(f"Failed to exchange verifier: {e}")