Blitzkriegfest
Blitzkriegfest

Reputation: 41

Refresh access token for Google Drive API in Postman

I am using Google Drive API to get the list of files on my google drive. I've got it working by getting an access token, client id and client secret in google cloud platform. My issue is, the token expires in 3600. I've tried this endpoint, https://www.googleapis.com/oauth2/v4/token

and put this in the request body,

{
  "client_id": "client_id",
  "client_secret": "client_secret",
  "refresh_token": "access_token",
  "grant_type": "refresh_token"
}

but is only returning

{
    "access_token": "new_access_token",
    "expires_in": 3552,
    "scope": "https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/drive",
    "token_type": "Bearer"
}

which doesn't refresh the token life.

is there anything I'm missing?

I am using it on postman first so that I can know it's working properly.

any help is appreciated.

Upvotes: 1

Views: 2739

Answers (2)

Blitzkriegfest
Blitzkriegfest

Reputation: 41

Turns out, you need to get refresh token from https://developers.google.com/oauthplayground/. You also need to authorize the redirect uri from Google Cloud Platform. Thanks for the guides. really helped a lot.

Upvotes: 0

camelBack
camelBack

Reputation: 778

Access tokens expire after a set time, and you need to make a call to request a new access token, using the refresh token you received. Generally, refresh tokens last longer and don't expire in a while, while access tokens are short lived.

This link is to the Google API doc: https://developers.google.com/identity/protocols/oauth2/web-server#offline

This is an SO similar question with useful information, and a useful answer: How to generate access token using refresh token through google drive API?

Basically, you can make an API call from postman to request for a new access token every time you need one (and use it in Postman for the call you need to make)

Upvotes: 1

Related Questions