【问题标题】:R retreive information from Eikon cloudR 从 Eikon 云中检索信息
【发布时间】:2021-02-11 16:46:44
【问题描述】:

我正在尝试从 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 的输入。我可以对我的代码进行哪些更改以使其正常工作?

【问题讨论】:

  • 为什么不在那个文档中使用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","&amp;username=", user,"&amp;scope=","trapi","&amp;app_id=",app_id, "&amp;password=", password,sep="") 和这个%40tr.com 在用户名中。我相信handler 应该等于body,但它只是显示auth_url。不知道怎么改,为什么会这样,

标签: r curl thomson-reuters-eikon


【解决方案1】:

我找到了如何访问 URL 的解决方案。在 github 中错误地写了 R 文件中的 app_id 应该等于 Reuters 中 App Key 生成器的代码。但是,app_id 和 client_id 是不同的东西,您应该从 App Key 生成器(不是 app_id)中添加 client_id=value。+ 也不要忘记在您的内容中包含 Trapi 等。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-06
    • 2011-12-10
    • 2017-08-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多