Working with gzip encoded GET / OAUTH response in R

I am new to both R and OAUTH. I learned a bit about using the coursera examples in the github API where the OAUTH request gave a clear text response, but now I'm trying to do something that's real to me and access the EVE-Online CREST OAUTH API, but instead of what I got when tried the github API (im using the "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": "",
...

      

I got this BINARY BODY answer:

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>

      

And to be honest, I have no idea what to do with it. I'm sure its gzip (I used the chrome extension postman to access the same information and the header says it is gzip encoded) but I don't know how to unpack it, maybe there is a standard way to handle the binary / gzip -answer, but my google foo failed me.

Here is the exact code I'm running:

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)

      

EDIT: YES !!! :) managed to figure it out :)

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

      

while reqular content (req) only produced raw binary data, the above translated it to json :)

+3


source to share


1 answer


As I wrote above, I needed more information about the content type and encoding used for such a content function:

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

      



The gzip part turned out to be handled automatically, but the problem was that the content type was being used using the EVE API. when i passed the desired content explicitly, the R type could read the data as json with no problem

+2


source







All Articles