import requests from dotenv import load_dotenv import os import base64 from urllib.parse import quote load_dotenv() TWITTER_CLIENT_ID = os.getenv('TWITTER_CLIENT_ID') TWITTER_SECRET = os.getenv('TWITTER_SECRET') encoded_client_id = quote(TWITTER_CLIENT_ID) encoded_client_secret = quote(TWITTER_SECRET) auth_string = f"{encoded_client_id}:{encoded_client_secret}" auth_base64 = base64.b64encode(auth_string.encode('utf-8')).decode('utf-8') url = "https://api.x.com/oauth2/token" headers = { "Authorization": f"Basic {auth_base64}", "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8", "Accept-Encoding": "gzip" } data = { "grant_type": "client_credentials" } response = requests.post(url, headers=headers, data=data) print(response.status_code) print(response.text)
Ripping my hair out. I am following the docs and I keep getting a 403 error. I have heard the X API is restrictive on the free tier but can you not even generate an OAuth token? Confirmed Client ID and Secret are correct.
submitted by /u/Due_Cap_7720
[link] [comments]
r/learnpython import requests from dotenv import load_dotenv import os import base64 from urllib.parse import quote load_dotenv() TWITTER_CLIENT_ID = os.getenv(‘TWITTER_CLIENT_ID’) TWITTER_SECRET = os.getenv(‘TWITTER_SECRET’) encoded_client_id = quote(TWITTER_CLIENT_ID) encoded_client_secret = quote(TWITTER_SECRET) auth_string = f”{encoded_client_id}:{encoded_client_secret}” auth_base64 = base64.b64encode(auth_string.encode(‘utf-8’)).decode(‘utf-8’) url = “https://api.x.com/oauth2/token” headers = { “Authorization”: f”Basic {auth_base64}”, “Content-Type”: “application/x-www-form-urlencoded;charset=UTF-8”, “Accept-Encoding”: “gzip” } data = { “grant_type”: “client_credentials” } response = requests.post(url, headers=headers, data=data) print(response.status_code) print(response.text) Ripping my hair out. I am following the docs and I keep getting a 403 error. I have heard the X API is restrictive on the free tier but can you not even generate an OAuth token? Confirmed Client ID and Secret are correct. submitted by /u/Due_Cap_7720 [link] [comments]
import requests from dotenv import load_dotenv import os import base64 from urllib.parse import quote load_dotenv() TWITTER_CLIENT_ID = os.getenv('TWITTER_CLIENT_ID') TWITTER_SECRET = os.getenv('TWITTER_SECRET') encoded_client_id = quote(TWITTER_CLIENT_ID) encoded_client_secret = quote(TWITTER_SECRET) auth_string = f"{encoded_client_id}:{encoded_client_secret}" auth_base64 = base64.b64encode(auth_string.encode('utf-8')).decode('utf-8') url = "https://api.x.com/oauth2/token" headers = { "Authorization": f"Basic {auth_base64}", "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8", "Accept-Encoding": "gzip" } data = { "grant_type": "client_credentials" } response = requests.post(url, headers=headers, data=data) print(response.status_code) print(response.text)
Ripping my hair out. I am following the docs and I keep getting a 403 error. I have heard the X API is restrictive on the free tier but can you not even generate an OAuth token? Confirmed Client ID and Secret are correct.
submitted by /u/Due_Cap_7720
[link] [comments]