Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Managing Google Sheets API Refresh Token

I am using Google Sheets for my website to store certain order information. The problem I'm dealing with is that the access_token expires within about an hour and the refresh_token lasts me a couple of days at most before it expires.

Once my refresh_token expires I have to:

  1. Physically log into Google with my app URL
  2. Accept Scopes and copy the auth code
  3. Make a code grant request to get issued a new refresh token

The above process is manual, tedious and unbearable after a month.

Is there a better way?

like image 501
Michiko Avatar asked Dec 06 '25 02:12

Michiko


1 Answers

The problem I'm dealing with is that the access_token expires within about an hour and the refresh_token lasts me a couple of days at most before it expires.

Refresh tokens only last seven days if your application is still in testing. Go to Google cloud console and set it to production. Your refresh token will then stop expiring.

enter image description here

I am using Google Sheets for my website to store certain order information.

If you are only using a sheet that you the developer control. This meaning that you are not accessing sheets owned by your users on their own google drive accounts. Then you should consider using a Service account. Should you be using a Google service account

like image 69
DaImTo Avatar answered Dec 08 '25 22:12

DaImTo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!