问题描述
我正在尝试从Eikon Elektron云平台获取数据。
我从https://github.com/Refinitiv/websocket-api/blob/master/Applications/Examples/R/market_price_authentication.R运行了以下代码:
library(curl)
> content = paste("grant_type=","password","&username=",user,"&password=",password,sep="")
> h <- new_handle(copypostfields = content)
> h
<curl handle> (empty)
> handle_setheaders(h,+ "Content-Type" = "application/x-www-form-urlencoded"
+ )
> handle_setopt(h,ssl_verifypeer = FALSE,ssl_verifyhost = FALSE)
> auth_url = paste("https://",auth_hostname,sep="")# ":",auth_port,"/getToken",sep="")
> auth_url
[1] "https://api.refinitiv.com/auth/oauth2/v1/token"
> req <- curl_fetch_memory(auth_url,**handle = h**)
> req
$url
[1] "https://api.refinitiv.com/auth/oauth2/v1/token"
$status_code
[1] 400
$type
[1] "application/json"
**> h
<curl handle> (https://api.refinitiv.com/auth/oauth2/v1/token)**
> res_headers = parse_headers(req$headers)
> auth_json_string = rawtochar(req$content)
> auth_json = fromJSON(auth_json_string)
> cat(toJSON(auth_json,pretty=TRUE,auto_unBox=TRUE))
{
"error": "invalid_request"
}
如您所见,我收到了无效的请求错误。我认为问题出在curl_fetch_memory
上,并且handle=h
使用的输入与auth_url
相同,但是应该使用与content
相似的输入。我可以在代码中进行哪些更改才能使其正常工作?
解决方法
我找到了如何访问URL的解决方案。在github中写错了R文件中的app_id应该等于路透社App Key生成器中的代码。但是,app_id和client_id是不同的东西,您应该在App Key生成器中添加client_id = value(而不是app_id)。+也不要忘记在内容中包含trapi等。