我正在尝试使用 instructions here 从命令行创建 OAuth token .我可以使用 curl
从命令行,并获得正确的响应
curl -u 'username:pwd' -d '{"scopes":["user", "gist"]}' \
https://api.github.com/authorizations
现在,我想使用
RCurl
在 R 中复制相同的内容或 httr
.这是我尝试过的,但两个命令都返回错误。谁能指出我在这里做错了什么?httr::POST(
'https://api.github.com/authorizations',
authenticate('username', 'pwd'),
body = list(scopes = list("user", "gist"))
)
RCurl::postForm(
uri = 'https://api.github.com/authorizations',
.opts = list(
postFields = '{"scopes": ["user", "gist"]}',
userpwd = 'username:pwd'
)
)
最佳答案
这个问题由来已久,但可能对某些人仍然有帮助:问题应该是 opts 参数以错误的方式传递(缺少 curlOptions 函数调用)。以下在不同的背景下对我有用:
result <- getURL(url,.opts=curlOptions(postfields=postFields))
(是的,据我所知,您可以对 POST 请求使用 getURL 函数)。
关于r - 使用 RCurl/httr 进行 Github 基本授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16121463/