【发布时间】:2019-08-26 16:11:36
【问题描述】:
我正在尝试编写一个 Google Apps 脚本来修改日历事件,因此我修改了一个示例以首先列出事件。当我尝试调试它时,它会在“events = Calendar.Events.list(calendarId, options);”这一行报告“未定义日历”的错误。
我已启用高级日历 API,并且我的脚本基于 Google 文档中的一个,因此我假设其中一个有效。我还需要做些什么来访问相关的对象和方法吗?
/*
Adapted from code in https://developers.google.com/apps-script/advanced/calendar
*/
function syncColourCode() {
var calendarId = CalendarApp.getDefaultCalendar();
var properties = PropertiesService.getUserProperties();
var fullSync = properties.getProperty('fullSync'); // sync status is stored in user properties
var options = {
maxResults: 100
};
var syncToken = properties.getProperty('syncToken'); // pointer token from last sync also stored in user properties
if (syncToken && !fullSync) { // if there is a sync token from last time and sync status has not been set to full sync
options.syncToken = syncToken; // adds the current sync token to the list of sync options
} else {
// Sync events from today onwards.
options.timeMin = new Date().toISOString(); //change to new Date().toISOString() from getRelativeDate(-1, 0).toISOString()
}
// Retrieve events one page at a time.
var events;
var pageToken;
do {
try {
options.pageToken = pageToken;
events = Calendar.Events.list(calendarId, options);
} catch (e) {
【问题讨论】:
-
您说“我已启用高级日历 API”,您是否看到它在高级谷歌服务面板和谷歌帐户 console.cloud.google.com/project/536834482971/apiui/api 中都处于活动状态?
标签: google-apps-script google-calendar-api