我对两者都很陌生:R和OAUTH。我在github API上学习了一些示例,其中OAUTH请求给出了明文响应,但现在我正在尝试做一些对我来说很实用的东西并且访问EVE-Online CREST OAUTH API而不是我得到的东西当我尝试使用github API时(即使用" httr" libary):
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": "",
...
我得到了这个BINARY BODY回复:
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扩展邮递员访问相同的信息,标题用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内容(req)只生成原始二进制数据,但上面将其翻译为json:)
答案 0 :(得分:2)
就像我上面写的那样,我需要做的是传递有关内容类型和内容函数编码的更多信息,如下所示:
result <- content(req, type = "application/json; charset=utf-8")
事实证明,gzip部分是自动处理的,但问题是EVE API使用的strage内容类型。当我明确地传递了所需的内容类型时,R能够以无需问题的方式读取数据