sonysony-lifelog-api

Get a weird reponse while trying to request data from the lifelog-api


I'm having problems with requesting data, it works fine when I try it in the API explorer but when I'm about to make a request from my webapp it just responds with a status of 200 and a body filled with weird characters.

The request:

const options = {  
      url: 'https://apigateway.lifelog.sonymobile.com/v1/users/me/activities',
      method: 'GET',
      headers: {
          'Accept': 'application/json',
          'Authorization': "Bearer " + access_token,
          'Accept-Encoding': 'gzip',         
          'Content-Encoding': 'gzip'


      }
  };
  request(options, function(err, res, body) {  
      console.log(JSON.stringify(res))
  });

The response:

{"statusCode":200,"body":"\u001f?\b\u0000\u0000\u0000\u0000\u0000\u0000\u0003\u0000\u0000\u0000???Xmo#E\u0012?+?_o?S?U?/????\u0017-???8V?Bh????u??\u0010V???W?\rd??e$\u0004? ????kMU?O=?w?]?_?????w?U?X.

The reponse keeps going and I guess that there is no point in copy/pasting all of it. I'm not sure if I actually need to send the token with the word Bearer in front but that was what gave me a status code of 200.


Solution

  • since your are requesting gzip encoding you need to tell request to expect gzipped content, just add gzip: true to you options.

    const options = {  
      url: 'https://apigateway.lifelog.sonymobile.com/v1/users/me/activities',
      method: 'GET',
      headers: {
          'Accept': 'application/json',
          'Authorization': 'Bearer ' + access_token,
          'Accept-Encoding': 'gzip',         
          'Content-Encoding': 'gzip'
      },
      gzip: true  
    };
    

    And then you should look at the body param instead of res of you just want the actual lifelog data

    request(options, function(err, res, body) {  
      console.log(body)
    });
    

    Hope this helps.

    Cheers