The JOKER
The JOKER

Reputation: 483

Getting error on using refreshToken for googleAPI to get new access token

My code to get the access token using a refresh token was working fine, but suddenly has stopped working and I'm getting exception as

unauthorized client and status code as 401.

Below is my sample code:

request({
         method: 'POST',
         headers: {
                 'Content-type': 'application/x-www-form-urlencoded'
                    },
        data: {
               client_id: XXXXX,
               client_secret: XXXXX,
               refresh_token: myRefresh_Token_Here,
                grant_type: 'refresh_token'
              },
        URL: "https://oauth2.googleapis.com/token"
      })
                .then(response => {
                    resolve(response);
            })
            .catch(exception => {
                reject(exception);
            });              

Below is the error what i get this i get in below object

exception.response.data
{"error":"unauthorized_client","error_description":"Unauthorized"}'

No other info, also the status code is 401

Upvotes: 1

Views: 1209

Answers (1)

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 117281

unauthorized client

Normally means that the client id and client secret you are using to pair with a refresh token is not the pair that was used to create the refresh token in the first place.

I would double check you have the correct client id and client secret or that someone didn't regenerate your secret on Google cloud console.

Upvotes: 1

Related Questions