Доступ к вложенным данным JSON в календаре Google - PullRequest
0 голосов
/ 11 апреля 2019

Я хочу прочитать статус занятости в открытом календаре Google.Пока что я могу прочитать ответ от Google, но я хочу сохранить список календарей. (Ключ) .busy [] в отдельной переменной.

 request.post({
  url: requestURL+browserKey,
  headers: {'content-type':'application/json'},
  body: JSON.stringify(data)
},function(error,response,body){
  if (error){
    //return error code
    return console.error(error);
  }
  console.log("The response from google is: " + body);
  //parse JSON object
  var googleResponse = JSON.parse(body);
  //print response from API
  console.log("Parsed data "+googleResponse);
  //print list of busy intervals
  lastBusy = JSON.strigify(googleReponse.calendars[0].busy);
  console.log("last busy on: "+lastBusy);
});

Результат следующий:

        The response from google is: {
     "timeMin": "2019-04-10T12:00:00.000Z",
     "timeMax": "2019-04-11T12:00:00.000Z",
     "calendars": {
      "xxxxxxxxxxxxx@group.calendar.google.com": {
       "busy": [
        {
         "start": "2019-04-11T05:00:00Z",
         "end": "2019-04-11T07:00:00Z"
        }
       ]
      }
     }
    }

Parsed data [object Object]
C:\Users\xxxxxxxxxxx\index.js:70
      lastBusy = JSON.strigify(googleReponse.calendars[0].busy);
                               ^

ReferenceError: googleReponse is not defined
...