将Curl转换为R编程POST功能

时间:2017-08-02 22:10:04

标签: r curl

我正在尝试将此代码转换为R编程:

curl -v -X POST -H "X-IBM-Client-Id:YOUR_CLIENT_ID" -H "X-IBM-Client-Secret:YOUR_CLIENT_SECRET" -H "Authorization: Bearer YOUR_ACCESS_TOKEN" -H "Content-Type:application/json" -H "Accept:application/json" https://api.ibm.com/watsonanalytics/run/data/v1/datasets -d '{ "description" :"1234" , "name" :"1234" }'

但是当我尝试时,它会给我一个未经授权的错误。

这是我正在使用的代码:

library(RCurl)
library(RJSONIO)
httpPOST("https://api.ibm.com/watsonanalytics/run/data/v1/datasets",
     content= c("description"="Test1",
                          "name"="Test1"),
     .opts = list(httpheader = c('Content-Type' = 'application/json', 
                                 'Accept' = 'application/json',
                                 'X-IBM-Client-Secret' = '123', 
                                 'X-IBM-Client-Id' = '123',
                                 'Authorization: Bearer'="")))

我非常感谢你的帮助 谢谢

0 个答案:

没有答案