我试图使用googleAuthR
从Google电子表格中请求数据。我需要使用此库而不是Jenny Bryan的googlesheets
,因为请求是具有多用户身份验证的闪亮应用程序的一部分。当请求范围不包含空格(如"Sheet1!A:B"
请求成功然而,当标签名称包含空格(如"'Sheet 1'!A:B"
或"\'Sheet 1\'!A:B"
,请求将失败并抛出这个错误:使用googleAuthR,httr和jsonlite向Google表格API失败的HTTP请求
Request Status Code: 400
Error : lexical error: invalid char in json text.
<!DOCTYPE html> <html lang=en>
(right here) ------^
马克·埃德蒙森的googleAuthR
使用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)
如何格式化对于T range
变量他请求工作?先谢谢您的帮助。
URLendcoding是最新版本的googleAuthR,0.6.2 – MarkeD