gpt4 book ai didi

r - 使用 googlesheets4 通过 Shiny 应用程序授权非交互式使用 googlesheets

转载 作者:行者123 更新时间:2023-12-04 08:58:17 30 4
gpt4 key购买 nike

我知道还有其他一些类似的问题围绕着 SO(例如 herehere ),但我想我会再试一次,因为其他人没有得到很多答案。
我有一个 Shiny 应用程序,允许其用户通过该应用程序提供输入,但这些用户需要跳过身份验证步骤。在以前版本的 googlesheets 中,我将工作表公开(对任何拥有链接的人)并避免了一些身份验证过程。在更新到 googlesheets4 时,我遇到了将更新的应用程序部署到 Shinyapps.io 的权限问题。这是我尝试过的内容以及我得到的结果的摘要。任何指针将不胜感激。
首先,根据 this gargle article 中的建议,我创建了一个服务帐户,下载了一个 JSON 服务帐户 token (格式为“project-name-12345678abc1.json”),并将其(暂时)保存在父应用程序文件夹中,在假设它需要与应用程序包一起上传。然后我启用了 Google Sheets API。
我已将以下命令放在应用程序的前面,在任何实质性内容之前:

  • gs4_deauth() ,因为谷歌表对任何拥有链接的人都是公开的,因此可能不需要 token 。
  • Following this article , gs4_auth(path = "project-name-12345678abc1.json") 。我还添加了 scopes 参数(如下)和 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")

  • 结果
    大多数组合给我的错误是“无法获得 Google 凭据”,然后建议我查看漱口水网站上的非交互式文章。一个异常(exception)是尝试 3,它提供以下错误消息 - 奇怪的是:

    Warning: Error in : Client error: (403) PERMISSION_DENIED

    • Client does not have sufficient permission. This can happen because the OAuthtoken does not have the right scopes, the client doesn't havepermission, or the API has not been enabled for the client project.

    关于我可能缺少什么的任何想法?该应用程序在本地运行良好。
    任何帮助表示赞赏。谢谢!

    最佳答案

    已使用 this (closed) Github issue 中确定的方法解决了此问题。 .
    关键是要完全按照以下步骤操作:

  • 调用 gs4_auth(cache = ".secrets") 一次 ,在浏览器中本地运行应用程序。
  • gs4_auth(cache = ".secrets", email = TRUE, use_oob = TRUE) 替换上面的行.
  • 将应用程序部署到 Shinyapps。

  • 我还清除了我之前保存的 token ,这可能很重要,但很难知道。
    如 Github 讨论中所述,包括 use_oob = TRUE可能没有必要。此外,此方法在 non-interactive auth 中有详细说明。漱口网站上的文章。

    关于r - 使用 googlesheets4 通过 Shiny 应用程序授权非交互式使用 googlesheets,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63699558/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com