gpt4 book ai didi

r - 在 R 中处理 gzip 编码的 GET/OAUTH 响应

转载 作者:行者123 更新时间:2023-12-04 12:11:14 24 4
gpt4 key购买 nike

我对两者都不熟悉:R 和 OAUTH。我在 github API 上使用 coursera 示例学到了一些东西,其中 OAUTH 请求给出了纯文本响应,但现在我正在尝试做一些对我来说实用的事情并访问 EVE-Online CREST OAUTH API,而不是我在尝试 github 时得到的API(我使用“httr”库):

Response [https://api.github.com/users/jtleek/repos]
Date: 2014-12-14 08:57
Status: 200
Content-type: application/json; charset=utf-8
Size: 154 kB
[
{
"id": 12441219,
"name": "ballgown",
"full_name": "jtleek/ballgown",
"owner": {
"login": "jtleek",
"id": 1571674,
"avatar_url": "https://avatars.githubusercontent.com/u/1571674?v=3",
"gravatar_id": "",
...

我得到了这个二元体响应:

Response [https://crest-tq.eveonline.com/market/10000002/orders/buy/?type=https://crest-tq.eveonline.com/types/185/]
Date: 2014-12-14 08:05
Status: 200
Content-type: application/vnd.ccp.eve.MarketOrderCollection-v1+json; charset=utf-8
Size: 7.61 kB
<BINARY BODY>

坦率地说,我不知道如何处理它。我很确定它的 gzip(我使用 chrome 扩展 postman 来访问相同的信息,并且标题说它是用 gzip 编码的)但是我不知道如何解压缩它,也许有处理二进制/gzip 响应的标准方法但是我的谷歌foo 让我失望了。

这是我正在运行的确切代码:

library(httr)
myapp <- oauth_app("my app name redacted", "my id redacted", "my secret redacted")
eve_token <- oauth2.0_token(oauth_endpoint(authorize = "https://login-tq.eveonline.com/oauth/authorize/",access = "https://login-tq.eveonline.com/oauth/token/"), myapp, scope = "publicData")
token <- config(token = eve_token)
req <- GET("https://crest-tq.eveonline.com/market/10000002/orders/buy/?type=https://crest-tq.eveonline.com/types/185/", token)

编辑:是的!!! :)设法弄清楚:)

result <- content(req, type = "application/json; charset=utf-8")

虽然 reqular content(req) 只生成原始二进制数据,但上面将其转换为 json :)

最佳答案

就像我上面写的那样,我需要做的是将更多关于内容类型和编码的信息传递给内容函数,如下所示:

result <- content(req, type = "application/json; charset=utf-8") 

事实证明,gzip 部分是自动处理的,但问题是 EVE API 使用的 strage 内容类型。当我明确传递所需的内容类型时,R 能够毫无问题地将数据读取为 json

关于r - 在 R 中处理 gzip 编码的 GET/OAUTH 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27467471/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com