tidyverse / googlesheets4

Google Spreadsheets R API (reboot of the googlesheets package)
https://googlesheets4.tidyverse.org
Other
360 stars 53 forks source link

Unable to `gs4_auth()` with `googledrive:drive_token()` #276

Closed davidski closed 1 year ago

davidski commented 1 year ago

I'm having problems following the advice under: https://googlesheets4.tidyverse.org/articles/drive-and-sheets.html to use a Google Service Account token to auth into Googlesheets. Under googlseheets4 1.0.1 and googledrive 2.0.0, the returned token from googledrive seems to be rejected by googlesheets.

options(gargle_verbosity = "debug")
googledrive::drive_deauth()
gs4_deauth()
googledrive::drive_auth(path = Sys.getenv("GOOGLE_TOKEN"))
gs4_auth(token = googledrive::drive_token())
Trying `token_fetch()`
trying `credentials_service_account()`
Error caught by `token_fetch()`:
Argument 'txt' must be a JSON string, URL or file.
trying `credentials_external_account()`
trying `credentials_app_default()`
trying `credentials_gce()`
trying `credentials_byo_oauth()`
`scopes` cannot be specified when user brings their own OAuth token
`scopes` are already implicit in the token
jennybc commented 1 year ago

That method is only intended for regular "user" tokens.

If you're using a service account token, just give that to each package.

googledrive::drive_auth(path = Sys.getenv("GOOGLE_TOKEN"))
googlesheets4::gs4_auth(path = Sys.getenv("GOOGLE_TOKEN"))
davidski commented 1 year ago

Ah ha! Thanks for the help. That works a treat.