Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Can't get Google credentials" Error on Shinyapps.io #308

Open
csb-gz opened this issue Dec 20, 2023 · 3 comments
Open

"Can't get Google credentials" Error on Shinyapps.io #308

csb-gz opened this issue Dec 20, 2023 · 3 comments

Comments

@csb-gz
Copy link

csb-gz commented Dec 20, 2023

I tried to follow instructions on post #184 by calling first gs4_auth(cache=".secrets") before deploying the app to shinyapps.io. In the system log, I can confirm the existence of cached token key file in ./secret folder. However, I still get "Can't get Google credentials." error on shinyapps.io. Thanks.

2023-12-20T15:31:42.518170+00:00 shinyapps[10831335]: gs4_auth(cache = ".secrets", email = TRUE, use_oob = TRUE)
2023-12-20T15:31:43.464681+00:00 shinyapps[10831335]: Error in gs4_auth(cache = ".secrets", email = TRUE, use_oob = TRUE) :
2023-12-20T15:31:43.468629+00:00 shinyapps[10831335]: Can't get Google credentials.
2023-12-20T15:31:43.472800+00:00 shinyapps[10831335]: ℹ Are you running googlesheets4 in a non-interactive session? Consider:
2023-12-20T15:31:43.477237+00:00 shinyapps[10831335]: • Call gs4_deauth() to prevent the attempt to get credentials.
2023-12-20T15:31:43.482349+00:00 shinyapps[10831335]: • Call gs4_auth() directly with all necessary specifics.
2023-12-20T15:31:43.486107+00:00 shinyapps[10831335]: ℹ See gargle's "Non-interactive auth" vignette for more details:
2023-12-20T15:31:43.489921+00:00 shinyapps[10831335]: ℹ https://gargle.r-lib.org/articles/non-interactive-auth.html
2023-12-20T15:31:43.493800+00:00 shinyapps[10831335]: Calls: local ... tryCatch -> tryCatchList -> tryCatchOne ->
2023-12-20T15:31:43.497625+00:00 shinyapps[10831335]: Execution halted
2023-12-20T15:31:43.501376+00:00 shinyapps[10831335]: Shiny application exiting ...
2023-12-20T15:47:25.464647+00:00 shinyapps[10831335]: Container event from container-8999208: stop

Have you tried my fix?

gs4_auth(cache = ".secrets")

Use this for the first time running the app in R to get the OAuth token. When deploying the app to the server, upload this .secrets folder too. Now replace the code above with the code below and upload the app to the server. Use_oob=TRUE is basically what did the trick for me.

gs4_auth(cache = ".secrets", email = TRUE, use_oob = TRUE)

Originally posted by @comicalequation in #184 (comment)

@jennybc
Copy link
Member

jennybc commented Feb 28, 2024

#184 seems to date back 2020 and a lot has changed about Google auth since then. I suspect that you need to take active steps to make sure that the same OAuth client is being used in both places, in order to prevent the token cache miss.

In your app code, prior to the gs4_auth() call, execute this:

options(gargle_oauth_client_type = "installed")

Alternatively, locally, before you get the token you embed in the app, execute this:

options(gargle_oauth_client_type = "web")

and either don't set the option in your Shiny app or set it also to "web".

The problem probably comes from that fact that locally we have to default to an "installed app" flow, whereas on a server (which would include shinyapps.io), we have to default to a "web app" flow.

@ZekeMarshall
Copy link

Thanks @jennybc , this works for me!

@seltinge-aclu
Copy link

We recently hit a similar issue deploying an .Rmd to Posit Connect; when we tried to use the instructions in this gargle vignette we got this error message from Google. Adding options(gargle_oauth_client_type = "web") to our deployed code solved it. Thanks @jennybc!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants