【发布时间】:2021-02-11 16:46:44
【问题描述】:
我正在尝试从 Eikon Elektron 云平台获取数据。
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 的输入。我可以对我的代码进行哪些更改以使其正常工作?
【问题讨论】:
-
为什么不在那个文档中使用
paste("https://", auth_hostname, ":", auth_port, "/getToken", sep="")这行代码? -
@ekoam 如果您有权访问 Eikon Api Playground,据说“提供用户和密码以获取令牌和刷新令牌。api.refinitiv.com/auth/oauth2/v1/token”。在正文下:grant_type=password&username=youruser%40tr.com&scope=trapi&client_id=000aaaa1111bbb555&password=yourpassword。在 Curl 下: curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: application/json" -H "Authorization: '"$STS_TOKEN"'" -d '' “api.refinitiv.com/auth/oauth2/v1/token”。所以,443 gettoken 应该被忽略。此外,在 Python 中,一切都适用于这个链接。
-
那么,您不应该在请求正文中还包含
scope和client_id吗?现在我只看到content中的三个参数:grant_type、用户名和密码。 -
@ekoam 是的,我还包括
content = paste("grant_type=", "password","&username=", user,"&scope=","trapi","&app_id=",app_id, "&password=", password,sep="")和这个%40tr.com在用户名中。我相信handler应该等于body,但它只是显示auth_url。不知道怎么改,为什么会这样,
标签: r curl thomson-reuters-eikon