Adi*_*rid 5 r google-authentication google-sheets shiny
的googleAuthR是R包包装了谷歌API客户端库(认证和API的进一步使用)。所述googlesheetsř包用于与谷歌片API(即,周围的谷歌片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"))
Run Code Online (Sandbox Code Playgroud)
对于该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")
Run Code Online (Sandbox Code Playgroud)
我想要一个流程,将的使用替换为gs_auth生成的令牌googleAuthR。
重要说明(稍后添加到此问题):
我想,也许使用googlesheets只在短期内是相关的,应该气馁,因为谷歌将要藐视它在2020年3月3日看到的消息
因此,@Aurèle的评论可能是这里的方法(希望googlesheets4最终获得其前任的所有能力)。从广义上讲,这个问题可能仍然很有趣。
我一直在努力通过身份验证googleAuthR,然后使用我的凭据来使用googlesheets4库读取表格。不幸的是,我仍然无法使其工作,但我在“pure”中找到了一个粗略的解决方法googleAuthR。使用gar_api_generator函数,您实际上可以调用 Google API 中允许的任何请求。
library(shiny)
library(googleAuthR)
options(shiny.port = 8787)
options(googleAuthR.redirect = "http://localhost:8787")
# JSON with you client data from GCP
gar_set_client(scopes = "https://www.googleapis.com/auth/spreadsheets.readonly",
web_json = "<YOUR_JSON>")
spreadsheet_key <- "<YOUR SHEET>"
read_googlesheet <- gar_api_generator(
baseURI = "https://sheets.googleapis.com/v4/",
http_header = 'GET',
path_args = list(spreadsheets = spreadsheet_key,
values = "A:U"), #column range
data_parse_function = function(x) x$values
)
## ui.R
ui <- fluidPage(title = "googleAuthR Shiny Demo",
tableOutput("gs")
)
## server.R
server <- function(input, output, session){
gar_shiny_auth(session)
output$gs <- renderTable({
df_raw <- read_googlesheet()
# make the first row of the dataset as a header
df <- df_raw[c(2:nrow(df_raw)), ]
colnames(df) <- df_raw[1, ]
df
})
}
shinyApp(gar_shiny_ui(ui, login_ui = gar_shiny_login_ui), server)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
102 次 |
| 最近记录: |