从谷歌日历检索数据到 gsheet,不工作

问题描述 投票:0回答:0

除了日志时间外没有给出任何结果,但在数据表上写下没有发现事件

我除了在数据表上看到我的事件,然后将这个脚本扩展到办公室里的每个人,以阅读一张总表,其中有人在当前办公室或家里工作。这是我个人日历的测试脚本。

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('Data');
  var logSheet = ss.getSheetByName('Log');
  var calendarId = "***My calender id***";
  var data = [];
  var today = new Date();
  var start = new Date(today.getFullYear(), today.getMonth(), today.getDate() - today.getDay(), 0, 0, 0); // Start of current week (Sunday)
  var end = new Date(today.getFullYear(), today.getMonth(), today.getDate() - today.getDay() + 6, 23, 59, 59); // End of current week (Saturday)
  var url = 'https://www.googleapis.com/calendar/v3/calendars/' + calendarId + '/events';
  var params = {
    method: 'get',
    headers: {
      Authorization: 'Bearer ' + ScriptApp.getOAuthToken()
    },
    contentType: 'application/json',
    muteHttpExceptions: true,
    payload: {
      timeMin: start.toISOString(),
      timeMax: end.toISOString(),
      singleEvents: true,
      orderBy: 'startTime'
    }
  };
  var response = UrlFetchApp.fetch(url, params);
  var events = JSON.parse(response.getContentText()).items || [];
  if (events.length > 0) {
    for (var i = 0; i < events.length; i++) {
      var event = events[i];
      var location = event.location || '';
      data.push([event.summary, event.start.dateTime, event.end.dateTime, location]);
    }
  } else {
    data.push(['No events found', '', '', '']);
  }
  sheet.getRange(1, 1, data.length, data[0].length).setValues(data);
  logSheet.appendRow([new Date()].concat(data));
}`
```

   
google-apps-script google-sheets google-calendar-api
© www.soinside.com 2019 - 2024. All rights reserved.