我正在尝试使用googleAuthR
. 我需要使用这个库而不是 Jenny Bryan 的库,googlesheets
因为该请求是具有多个用户身份验证的闪亮应用程序的一部分。当请求范围不包含空格时(例如"Sheet1!A:B"
,请求成功。但是,当标签名称包含空格时(例如"'Sheet 1'!A:B"
,"\'Sheet 1\'!A:B"
请求失败并丢弃此错误:
Request Status Code: 400
Error : lexical error: invalid char in json text.
<!DOCTYPE html> <html lang=en>
(right here) ------^
Mark EdmondsongoogleAuthR
用于jsonlite
解析 JSON。我认为这个错误来自jsonlite
,但我不知道如何修复它。这是重新创建问题的最小示例:
library(googleAuthR)
# scopes
options("googleAuthR.scopes.selected" = "https://www.googleapis.com/auth/spreadsheets.readonly")
# client id and secret
options("googleAuthR.client_id" = "XXXX")
options("googleAuthR.client_secret" = "XXXX")
# request
get_data <- function(spreadsheetId, range) {
l <- googleAuthR::gar_api_generator(
baseURI = "https://sheets.googleapis.com/v4/",
http_header = 'GET',
path_args = list(spreadsheets = spreadsheetId,
values = range),
pars_args = list(majorDimension = 'ROWS',
valueRenderOption = 'UNFORMATTED_VALUE'),
data_parse_function = function(x) x)
req <- l()
req
}
# authenticate
gar_auth(new_user = TRUE)
# input
spreadsheet_id <- "XXXX"
range <- "'Sheet 1'!A:B"
# get data
df <- get_data(spreadsheet_id, range)
我应该如何格式化range
变量以使请求起作用?在此先感谢您的帮助。