【问题标题】:Using RCurl/httr for Github Basic Authorization使用 RCurl/httr 进行 Github 基本授权
【发布时间】:2013-04-13 20:11:09
【问题描述】:

我正在尝试使用 instructions here 从命令行创建 OAuth 令牌。我可以在命令行中使用curl,并得到正确的响应

curl -u 'username:pwd' -d '{"scopes":["user", "gist"]}' \
  https://api.github.com/authorizations

现在,我想使用 RCurlhttr 在 R 中复制相同的内容。这是我尝试过的,但两个命令都返回错误。谁能指出我在这里做错了什么?

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列表中,尝试添加httpauth = 1L
  • 尝试使用详细标志来查看到底发生了什么
  • authenticate 中设置type = "basic"
  • httpauth = 1L 有效。仍然无法让httr 工作。 @hadley,我在哪里可以在 httr 的 POST 命令中添加详细信息。
  • rgithub 包在这里可能会有所帮助。

标签: r rcurl httr


【解决方案1】:

这个问题由来已久,但可能对某些人仍然有帮助:问题应该是 opts 参数以错误的方式传递(缺少 curlOptions 函数调用)。以下内容在不同的情况下对我有用:

result <- getURL(url,.opts=curlOptions(postfields=postFields))

(是的,据我所知,您可以将 getURL 函数用于 POST 请求)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-08
    • 1970-01-01
    • 1970-01-01
    • 2014-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多