【发布时间】:2014-09-08 23:25:48
【问题描述】:
我是 Javascript 和 Google 脚本的新手,并且正在学习 JavaScript 和 Google 脚本,我正在尝试编写一个脚本来检查日历是否在某个时间忙碌。根据https://developers.google.com/google-apps/calendar/v3/reference/freebusy/query,这应该以以下格式返回:
{
"kind": "calendar#freeBusy",
"timeMin": datetime,
"timeMax": datetime,
"calendars": {
"busy": [{"start": datetime,"end": datetime}]
}
}
但是,我正在使用以下代码(简化以重现问题):
function checkResource() {
var calendarId = [The Calendars ID removed for privacy];
var check = {
items: [{id: calendarId, busy: 'Active'}],
timeMax: "2014-09-09T21:00:31-00:00",
timeMin: "2014-09-09T17:00:31-00:00"
};
var response = Calendar.Freebusy.query(check);
Logger.log('Response: '+ response);
Logger.log('Response Calendars: '+ response.calendars.calendarId);
for (var property in response){
Logger.log('Property: '+ property);
Logger.log('Property Value: '+ response[property]);
}
for (var calendarValue in response){
Logger.log('Calendar Value: '+ response.calendars.calendarValue);
};
}
它为我记录了所有日历属性,但由于某种原因,当我尝试进入嵌套的“忙碌”对象时,除了“[对象对象]”或“未定义”之外不会返回任何内容。
日历在这段时间故意忙碌(2014-09-09T18:00:00Z 有一个事件持续一个小时),当我记录整个函数时你可以看到这一点(Logger.log(' Response: '+ response); 显示日历 ID、'busy' 以及开始和结束时间),所以我的代码显然出错了。
任何帮助都会很棒。
【问题讨论】:
-
感谢您揭示这个我不知道的功能 :-) 实际上非常有趣!
标签: javascript google-apps-script google-api