- Create a service account, I don't exactly remember but I think you'll get an email after creating a service account.
- Add this email as an editor to your Google Sheet (Please research on this, I don't exactly remember)
Below code can be used on Edge (Cloudflare Workers)
You probably get the expiry time of the token in the token itself, you can use that to refetch new token again.