【发布时间】:2020-02-02 18:46:06
【问题描述】:
googleAuthR 是一个 R 包,它封装了 google API 客户端库(API 的身份验证和进一步使用)。 googlesheets R 包用于与 google sheet API 集成(即,围绕 google sheet API 的包装)。
这些包中的每一个都有自己独立的 OAuth2.0 进程。我使用googleAuthR 来登录一个闪亮的应用程序,该应用程序又使用googlesheets 库(但使用不同的身份验证过程)。
问题:我们如何将googlesheets 包设置为也使用初始googleAuthR 凭据?
这是我正在使用的过程(在闪亮的应用程序中):
对于我正在使用的googleAuthR 登录:
options(googleAuthR.webapp.client_secret = "***REMOVED_FROM_EXAMPLE***")
options(googleAuthR.webapp.client_id = "***REMOVED_FROM_EXAMPLE***")
options(googleAuthR.scopes.selected = c("https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/spreadsheets"))
对于googlesheets 包,我目前正在使用一个预先注册的(单独的)令牌,该令牌已保存到 RDS 文件中,正如包的小插图中所建议的那样:
suppressMessages(gs_auth(token = "googlesheets_token.rds", verbose = FALSE))
gsheet_log <- googlesheets::gs_url("https://docs.google.com/spreadsheets/d/***REMOVED_FROM_EXAMPLE***/edit#gid=0")
我想要一个流程,将 gs_auth 的使用替换为 googleAuthR 生成的令牌。
重要提示(稍后添加到此问题中):
我认为googlesheets 的使用可能只适用于短期,并且应该不鼓励,因为谷歌将在 2020 年 3 月 3 日弃用它see message
因此@Aurèle 的评论可能是这里的方法(希望googlesheets4 最终将获得其前身的所有功能)。从广义上讲,这个问题可能仍然很有趣。
【问题讨论】:
-
考虑(尚未在 CRAN 上)继任者
googlesheets4github.com/tidyverse/googlesheets4 ,它依赖于gargle进行身份验证(在 CRAN 上,cloud.r-project.org/web/packages/gargle/index.html ) -
谢谢,但目前 googlesheets4 还没有 googlesheets 的很多功能,例如,向现有工作表添加单行。
-
我的解决方法是使用
googledrive包下载文件,然后使用readxl或readr读取文件
标签: r google-sheets shiny google-authentication