How to take take access tokens from oauth2

I’m having problems on taking the access token from the oauth2 platform with python.

Currently, that’s what I’m using on my post request:

def token(self):
        client_id=ID_DO_CLIENTE
        client_secret=SECRET_TOKEN
        grant_type='client_credentials'

        response = requests.post("https://oauth2.googleapis.com/token",
                                auth=(client_id, client_secret),
                                 data={'grant_type':grant_type,'client_id':client_id,'client_secret':client_secret})
        print(response.text)

This specific code is returning the following error:

{
  "error": "unsupported_grant_type",
  "error_description": "Invalid grant_type: "
}

But I don’t think the problem is the grant_type, since I’ve tried everything I’ve found online to solve this.

Anyway, if there’s any info missing, please let me know. Please help !

Source: Python Questions

LEAVE A COMMENT