我正在试验 R,我想知道如何使用库 httr 或 rcurl 从 API 获取一些数据。
例如,在终端中使用 curl 我可以做到这一点,它会为我提供我想要的数据:
curl -X GET "https://some.webpage.com/api/v1/accounts/self/profile" -H "accept: application/json" -H "token-auth: 72124asfin393483feifefi92835w345"
注意: token key 是随机字符集
不幸的是,当我尝试在 R 中重现这个时,我失败了,我尝试使用类似的东西:
> library(httr)
> c <- GET("https://some.webpage.com/api/v1/accounts/self/profile?token- auth=72124asfin393483feifefi92835w345"
或者这个:
> url = "https://some.webpage.com/api/v1/accounts/self/profile"
> key = "{72124asfin393483feifefi92835w345}"
> a <- GET(url, add_headers(Authorization = paste("Bearer", key, sep = " ")))
不幸的是,当我在 Rstudio 中尝试这个时,我总是得到这个错误:
[1] "'token-auth' has to be provided for authentication."
有关此特定 API 调用的更多信息:
This is the documentation
所以我想我显然在 url 组合上做错了,我如何让它与 R 一起工作?我很困惑,我在 R 中找到了一些关于 API 的文档,但没有解释如何使用 token 。谢谢
最佳答案
正确的解决方案是MrFlick所说的:
Then try a <- GET(url, add_headers("token-auth" = key)). And make sure you don't have the braces in your key string.
https://stackoverflow.com/questions/60063694/
相关文章:
c++ - 错误 : cannot add a default template argument
javascript - 使用 axios 使用 get 方法发送嵌套的 json 数据
javascript - 数组中的对象 数组中的对象 数组中的对象 JavaScript - 搜索
python - Pyspark - 将多列数据组合成一个跨行分布的列
python - 如何计算具有特定扩展名或名称的文件中的文件数?
php - 是否有一个 Wordpress php 函数可以只返回自定义 Logo 图像的 URL(