更新时间:2023-02-16 15:38:10
在此特定用例中-与画布API -请求的标头中需要其他信息。
In this particular use case—working with the Canvas API—additional information is required in the header of the request.
使用 httr R包中的code> GET 函数,使用 add_header
参数提供参数,包括您的oauth2键。
Using the GET
function from the httr
R package, use the add_header
parameter to supply the argument including your oauth2 key.
如果您不想将密钥硬编码到请求中,请使用选项1(推荐)。或者,使用选项2并将密钥作为字符串插入。但是在两种情况下,键都是 Bearer。
Use Option 1 if you don't want to hard code your key into the request (recommended). Or, use Option 2 and insert the key as a string. But in both cases, "Bearer " precedes the key.
# Set Up
url = "https://canvas.{institution}.edu/api/v1/courses"
key = "{secret_key}"
# OPTION 1
GET(url, add_headers(Authorization = paste("Bearer", key, sep = " ")))
# OPTION 2
courses.request = GET(url, add_headers(Authorization = "Bearer {secretkey}"))
其他任何人都可以解释其他原因吗? ns为什么OP的示例没有起作用?
Can anyone else explain other reasons why the OP's examples didn't work?