0

我是新手googlesheet4。我想部署一个从googlesheet 文件中动态提取数据的应用程序,这样应用程序的用户至少需要通过他们的 google 电子邮件进行身份验证

一切都在我的本地机器上运行,并且该应用程序已成功部署。但是在我打开应用程序后,应用程序立即断开连接,并在闪亮的应用程序日志中留下这些错误消息:

Warning: Error in : Can't get Google credentials.
Are you running googlesheets4 in a non-interactive session? Consider:
  * `gs4_deauth()` to prevent the attempt to get credentials.
See gargle's "Non-interactive auth" vignette for more details:

我试图调整这些例子:1 2没有得到结果。这是我的虚拟代码:

library("googlesheets4")
library("googledrive")
library("shiny")

options(gargle_oauth_cache = ".secrets")
drive_auth(cache = ".secrets", email = T)
gs4_auth(token = drive_token())
ui <- # Define UI for application that plots random distributions 
  fluidPage(
    
    # Application title
    titlePanel("Hello Shiny!"),
    
    # Sidebar with a slider input for number of observations
    sidebarLayout(
      sidebarPanel(
        sliderInput("obs", 
                    "Number of observations:", 
                    min = 1, 
                    max = 1000, 
                    value = 500),
        actionButton(
          "add",
          "Add new entry")
      ),
      
      # Show a plot of the generated distribution
      mainPanel(
        "Check your googlesheet!!"
      )
    )
  )

server <- function(input, output, session) {
  #
  observeEvent(input$add, {

    wb <- "https://docs.google.com/spreadsheets/d/1Qo0Lssji-2NLxHA-QwNvoDqdiKppoTikRflN0ltLJ7U/edit#gid=0"
    df <- read_sheet(wb)
    df

  })
}

shinyApp(ui, server)

运行上面的代码后,我收到以下错误消息:

Listening on http://127.0.0.1:6611
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.
  * Request had insufficient authentication scopes.

Error details:
  * reason: ACCESS_TOKEN_SCOPE_INSUFFICIENT
  * domain: googleapis.com
  * metadata.method: google.apps.sheets.v4.SpreadsheetsService.GetSpreadsheet
  * metadata.service: sheets.googleapis.com
  [No stack trace available]

任何帮助将不胜感激。

4

0 回答 0