1

I'm trying to access a private Google Sheet in a daily cronjob in order to populate a database. This job runs on a remote server. Currently I'm using the method outlined here to access the spreadsheet. The caveat is that every time the access token expires, a user has to manually go in and authenticate the request for a new access token by logging into their Google account. Is there a way to obtain an access token without user interaction?

koko
  • 158
  • 1
  • 7
  • Who is the script meant for? Users on your domain only, or also users on other domains/Google accounts? – Rafa Guillermo Jul 20 '21 at 07:58
  • @RafaGuillermo it's meant for users on my domain only. Ideally I would just have one account (like a service account) whose credentials are used for the script. – koko Jul 20 '21 at 09:02
  • As far as I know, some Google APIs can be accessed using service account credentials [without OAuth](https://developers.google.com/identity/protocols/oauth2/service-account?authuser=1#jwt-auth). But I'm not sure how to get this to work with the Sheets API (if it even does work) – koko Jul 20 '21 at 09:08
  • you then need to construct a JWT; check out my answer [here](https://stackoverflow.com/questions/61915432/google-oauth-using-domain-wide-delegation-and-service-account/61932919#61932919) which uses Drive, though AFAIK it also works with Sheets – Rafa Guillermo Jul 20 '21 at 10:18

0 Answers0