hello therem i have a problem with posting authorization code to create an access tokens (OAuth 2.0 Making requests on behalf of users | Docs | Twitter Developer Platform) specifically in step 3. Im using requests module in python, my code:

CLIENT_ID = os.environ["client_id"]

data=f"code={AUTH_CODE}&grand_type=authorization_code&client_id={CLIENT_ID}&redirect_uri=https://twitter.com&code_verifier=challenge"

encoded = base64.b64encode(bytes(f"{CLIENT_ID}:{os.environ['client_secret']}", "utf-8"))

res = requests.request(
    "POST",
    "https://api.twitter.com/2/oauth2/token",
    data=data,
    headers={
        "Authorization": f"Basic {str(encoded)}"
    }
)

I got

{"error":"invalid_request","error_description":"Missing required parameter [client_id]."}

And 400 status code, which is weird since i specified it in data

Setting the “Content-Type” header to “application/x-www-form-urlencoded” solved this problem for me.

2 Likes

Ahh thanks alot! It works.

1 Like