I know there are a few other similar questions floating around SO (e.g., here and here), but I thought I'd try again, as the others have not gotten many answers.
I have a Shiny app that allows its users to provide input through the app, but these users need to skip the authentication step. In the previous version of googlesheets
I made the sheet public (to anyone with the link) and avoided some of the authentication process. In updating to googlesheets4
I've run into permissions issues with deploying the updated app to shinyapps.io. Here is the summary of what I've tried, and what results I've gotten. Any pointers would be much appreciated.
First, based on the recommendations in this gargle
article I created a service account, downloaded a JSON service account token (with format "project-name-12345678abc1.json"), and have saved it (for now) in the parent app folder, under the assumption that it needs to be uploaded with the app bundle. Then I enabled the Google Sheets API.
I've put the following commands in the front of the app, ahead of anything substantial:
gs4_deauth()
, since the google sheet is public to anyone with the link and therefore might not require a token.
Following this article, gs4_auth(path = "project-name-12345678abc1.json")
. I've also added the scopes
argument (as below), and use_oob=TRUE
.
credentials_service_account(scopes = "https://www.googleapis.com/auth/spreadsheets", path = "project-name-12345678abc1.json")
.
credentials_app_default(path = "project-name-12345678abc1.json")
Results
Most combinations give me errors saying "Can't get Google credentials" and then advising that I look at the non-interactive article on the gargle site. The one exception is Attempt 3, which provides the following error message instead - strangely promising:
Warning: Error in : Client error: (403) PERMISSION_DENIED
- Client does not have sufficient permission. This can happen because the OAuth token does not have the right scopes, the client doesn't have permission, or the API has not been enabled for the client project.
Any ideas on what I might be missing? The app works fine locally.
Any help is appreciated. Thanks!
This problem has been addressed using the approach identified in this (closed) Github issue.
The key is to follow these steps exactly:
gs4_auth(cache = ".secrets")
once, running the app locally in the browser.gs4_auth(cache = ".secrets", email = TRUE, use_oob = TRUE)
.I also cleared the previous tokens I had saved, which might have been important, though hard to know.
As noted in the Github discussion, including use_oob = TRUE
is probably not necessary. Additionally, this approach is detailed in the non-interactive auth article on the gargle site.