Hi all, I'm using the googledrive package by way of the googlesheets4 package, and I'd like to grant non-interactive access to a Google Sheet (e.g. so a cron job can make updates to a sheet on my behalf).
The steps I've taken, I think should work, but clearly I'm missing something here :-/
In my GCS account, I created a Service Account. This returned a JSON token file, which I stored.
In my Google Sheet, I granted edit permissions to the email address associated with the Service Account (which is one of the fields in the token JSON file).
Now my R program looks like so:
library(googledrive)
library(googlesheets5)
drive_auth(path = "/path/to/my/service/account/token/file.json")
sheets_sheet_add("id-of-my-sheet", "new worksheet name")
That last call starts the OAuth2.0 dance, which is exactly what I'm trying to avoid by using the service account's token.
Any ideas for how to allow a background R process to access my Google Sheet without the OAuth2.0 dance?
googlesheets4 is probably starting an OAuth2.0 dance because the sheets package doesn't see the service account token credentials, and instead is trying to create a new OAuth token for you. I have been able to use both packages successfully using this method of directly calling the service account location for both drive_auth and sheets_auth.
edited to add more detail and hopefully be more helpful.
Hi!
I was struggling with this issue also. I reviewed all the suggestions in Non-interactive auth, but with no luck. I tried also the Service Account Token, it did not work. This was frustrating taking into account the simple process I wanted to do (modify a googlesheet through a ShinyApp). Here is the solution I have found, it might be useful for you: