将CURL请求转换为R?

时间:2017-01-25 21:01:35

标签: r curl http-headers

我正在尝试将CURL请求转换为R.这里是CURL:

curl -v -u random_api_key -H "Content-Type: application/json" -X GET 'https://domain.freshdesk.com/api/v2/tickets'

我试图把它变成

require(RJSONIO) tickets = fromJSON('https://domain.freshdesk.com/api/v2/tickets?u=random_api_key')

但这引起了服务器响应:

"invalid_credentials" "You have to be logged in to perform this action."

然后我尝试使用不同的库并明确设置标题:

library(httr)   
library(rjson)  
query <- "https://domain.freshdesk.com/api/v2/tickets"
getdata<-GET(query, query = list(User-Agent:"random_api_key", Content-Type:"application/json"))
fromJSON(content(getdata,type="text"))

但是这给了我错误:

Error in named(list(...)) : object 'User' not found

不知道从哪里开始。任何帮助,将不胜感激。谢谢!

0 个答案:

没有答案