Javascript 为什么';忙/闲';谷歌日历API回来的时间到了';未定义';?
我是Javascript和Google脚本的新手,我正在尝试编写一个脚本来检查日历在某个时间是否繁忙。根据,应以以下格式返回:Javascript 为什么';忙/闲';谷歌日历API回来的时间到了';未定义';?,javascript,google-apps-script,google-api,Javascript,Google Apps Script,Google Api,我是Javascript和Google脚本的新手,我正在尝试编写一个脚本来检查日历在某个时间是否繁忙。根据,应以以下格式返回: { "kind": "calendar#freeBusy", "timeMin": datetime, "timeMax": datetime, "calendars": { "busy": [{"start": datetime,"end": datetime}] } } 但是,我使用以下代码(简化以重现问题): 它为我记录所有日历属性,
{
"kind": "calendar#freeBusy",
"timeMin": datetime,
"timeMax": datetime,
"calendars": {
"busy": [{"start": datetime,"end": datetime}]
}
}
但是,我使用以下代码(简化以重现问题):
它为我记录所有日历属性,但由于某种原因,当我尝试进入嵌套的“忙碌”对象时,除了“[object object]”或“undefined”之外,不会返回任何内容
在这段时间内,日历有意处于繁忙状态(2014-09-09T18:00:00Z有一个事件持续一个小时),当我记录整个函数(Logger.log('Response:'+Response')时,您可以看到这一点;显示日历ID,'busy'以及开始和结束时间),因此我的代码显然出错了
任何援助都将是巨大的 在记录器中进行“深入”查看后,我发现以下代码似乎返回了您想要的结果:
function checkResource() {
var calendarId = ["_________________o9mvpo5r5cvb5nb4cg@group.calendar.google.com"];
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.kind)
Logger.log('Time MIN = '+response.timeMin)
Logger.log('Time MAX = '+response.timeMax)
Logger.log('busy start = '+response.calendars[calendarId].busy[0].start)
Logger.log('busy end = '+response.calendars[calendarId].busy[0].end)
}
结果日志:
[14-09-10 15:50:51:724 CEST] calendar#freeBusy
[14-09-10 15:50:51:724 CEST] Time MIN = 2014-09-09T17:00:31.000Z
[14-09-10 15:50:51:724 CEST] Time MAX = 2014-09-09T21:00:31.000Z
[14-09-10 15:50:51:725 CEST] busy start = 2014-09-09T17:00:31Z
[14-09-10 15:50:51:725 CEST] busy end = 2014-09-09T18:00:00Z
从基本值记录:
[14-09-10 15:47:37:676 CEST] Response: {"kind":"calendar#freeBusy","timeMin":"2014-09-09T17:00:31.000Z","calendars":{"_____________9mvpo5r5cvb5nb4cg@group.calendar.google.com":{"busy":[{"start":"2014-09-09T17:00:31Z","end":"2014-09-09T18:00:00Z"}]}},"timeMax":"2014-09-09T21:00:31.000Z"}
源于您的完整脚本:
function checkResource() {
var calendarId = ["________________vb5nb4cg@group.calendar.google.com"];
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.kind)
Logger.log('Time MIN = '+response.timeMin)
Logger.log('Time MAX = '+response.timeMax)
Logger.log('busy start = '+response.calendars[calendarId].busy[0].start)
Logger.log('busy end = '+response.calendars[calendarId].busy[0].end)
Logger.log('Response: '+ response);
}
谢谢你透露这个我不知道的功能:-)其实很有趣!谢谢,这给了我解决问题所需要的东西!由于某些原因,当不存在事件时,它抛出“Start is undefined”,并且仅当事件确实存在时才起作用。不知道为什么它不只是返回一个空值。。。。我已经把你的建议标为“接受”。
function checkResource() {
var calendarId = ["________________vb5nb4cg@group.calendar.google.com"];
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.kind)
Logger.log('Time MIN = '+response.timeMin)
Logger.log('Time MAX = '+response.timeMax)
Logger.log('busy start = '+response.calendars[calendarId].busy[0].start)
Logger.log('busy end = '+response.calendars[calendarId].busy[0].end)
Logger.log('Response: '+ response);
}