Googlesheets authorization on shinyapps.io

I'm attempting to get write access to a googlesheet from a shiny app using the "service account token" approach described in https://gargle.r-lib.org/articles/non-interactive-auth.html. In my app, this involves two lines:

googledrive::drive_auth(path  = "learnrcache-efcb19f92072.json")
passwd_df <-  sheets_read(key)

All works well when I am running the app on my development computer [I was wrong here.], but when I deploy to shinyapps.io I get this error:

Error in value[[3L]](cond) : Can't get Google credentials.
Are you running googlesheets4 in a non-interactive session? Consider:
  * `sheets_deauth()` to prevent the attempt to get credentials.
  * Call `sheets_auth()` directly with all necessary specifics.
See gargle's "Non-interactive auth" vignette for more details:
https://gargle.r-lib.org/articles/non-interactive-auth.html
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted

Any suggestions? I'm trying to create a package for instructors to log events from learnr tutorials in order to support the COVID-19 movement to online learning.

I haven't used the gargle package myself but I have authenticated with googlesheets in the past. Has learnrcache-efcb19f92072.json been uploaded to the shinyapps directory? I think that may have been for a one-time session only.

You may want to try googledrive::drive_auth_configure() first to store a key for use in downstream requests. Then you'll use your API key for all requests.

Thanks, Tanya. Indeed I did have learnrcache-efcb19f92072.json uploaded to the shinyapps directory.

I tried your suggestion to use googledrive::drive_auth_configure(), or at least I think I tried it. This is what I did

  1. Went to https://console.cloud.google.com/apis/credentials to create an API key.
  2. Ran oaauth_app()
myapp <- httr::oauth_app(
    "markr", # the name of the package implementing the system
    key = "the_key_I_got_in_step_1", 
    "a character string to use as a secret")
  1. In the app, called

googledrive::drive_auth_configure(app = myapp, api_key = mykey)

This doesn't work, either on my development computer or (not surprisingly) on shinyapps.io

Is it the same error and if not can you post it?

I got this to work by following the example here:

1 Like