Class Calendar

日历

表示用户拥有或订阅的日历。

方法

方法返回类型简介
createAllDayEvent(title, date)CalendarEvent创建新的全天活动。
createAllDayEvent(title, startDate, endDate)CalendarEvent创建可以持续多天的新全天活动。
createAllDayEvent(title, startDate, endDate, options)CalendarEvent创建可以持续多天的新全天活动。
createAllDayEvent(title, date, options)CalendarEvent创建新的全天活动。
createAllDayEventSeries(title, startDate, recurrence)CalendarEventSeries创建新的全天活动系列。
createAllDayEventSeries(title, startDate, recurrence, options)CalendarEventSeries创建新的全天活动系列。
createEvent(title, startTime, endTime)CalendarEvent创建新的活动。
createEvent(title, startTime, endTime, options)CalendarEvent创建新的活动。
createEventFromDescription(description)CalendarEvent根据自由形式的说明创建事件。
createEventSeries(title, startTime, endTime, recurrence)CalendarEventSeries创建新的活动系列。
createEventSeries(title, startTime, endTime, recurrence, options)CalendarEventSeries创建新的活动系列。
deleteCalendar()void永久删除日历。
getColor()String获取日历的颜色。
getDescription()String获取日历的说明。
getEventById(iCalId)CalendarEvent获取具有指定 ID 的事件。
getEventSeriesById(iCalId)CalendarEventSeries获取具有指定 ID 的活动系列。
getEvents(startTime, endTime)CalendarEvent[]获取指定时间范围内发生的所有事件。
getEvents(startTime, endTime, options)CalendarEvent[]获取指定时间范围内发生且满足指定条件的所有事件。
getEventsForDay(date)CalendarEvent[]获取指定日期发生的所有事件。
getEventsForDay(date, options)CalendarEvent[]获取指定日期发生且满足指定条件的所有事件。
getId()String获取日历的 ID。
getName()String获取日历的名称。
getTimeZone()String获取日历的时区。
isHidden()Boolean确定日历是否在界面中隐藏。
isMyPrimaryCalendar()Boolean确定日历是否为有效用户的主日历。
isOwnedByMe()Boolean确定日历是否归您所有。
isSelected()Boolean确定日历的活动是否在界面中显示。
setColor(color)Calendar设置日历的颜色。
setDescription(description)Calendar设置日历的说明。
setHidden(hidden)Calendar设置是否在界面中显示日历。
setName(name)Calendar设置日历的名称。
setSelected(selected)Calendar设置是否在界面中显示日历的活动。
setTimeZone(timeZone)Calendar设置日历的时区。
unsubscribeFromCalendar()void为用户退订日历。

详细文档

createAllDayEvent(title, date)

创建新的全天活动。

// Creates an all-day event for the moon landing and logs the ID.
var event = CalendarApp.getDefaultCalendar().createAllDayEvent('Apollo 11 Landing',
    new Date('July 20, 1969'));
Logger.log('Event ID: ' + event.getId());

参数

名称类型说明
titleString活动的标题。
dateDate活动的日期(仅使用日期;忽略时间)。

弃踢回攻

CalendarEvent - 所创建的事件。

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

createAllDayEvent(title, startDate, endDate)

创建可以持续数天的新全天活动。

// Creates an all-day event for the Woodstock festival (August 15th to 17th) and logs the ID.
var event = CalendarApp.getDefaultCalendar().createAllDayEvent('Woodstock Festival',
    new Date('August 15, 1969'),
    new Date('August 18, 1969'));
Logger.log('Event ID: ' + event.getId());

参数

名称类型说明
titleString活动的标题。
startDateDate活动的开始日期(仅使用日期,系统会忽略时间)。
endDateDate活动的结束日期(仅使用日期;时间会被忽略)。结束日期不包括在内。

弃踢回攻

CalendarEvent - 所创建的事件。

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

createAllDayEvent(title, startDate, endDate, options)

创建可以持续数天的新全天活动。

// Creates an all-day event for the Woodstock festival (August 15th to 17th) and logs the ID.
var event = CalendarApp.getDefaultCalendar().createAllDayEvent('Woodstock Festival',
    new Date('August 15, 1969'),
    new Date('August 18, 1969'),
    {location: 'Bethel, White Lake, New York, U.S.', sendInvites: true});
Logger.log('Event ID: ' + event.getId());

参数

名称类型说明
titleString活动的标题。
startDateDate活动的开始日期(仅使用日期,系统会忽略时间)。
endDateDate活动的结束日期(仅使用日期;时间会被忽略)。结束日期不包括在内。
optionsObject一个用于指定高级参数的 JavaScript 对象,如下所示。

高级参数

名称类型说明
descriptionString事件的说明。
locationString活动地点。
guestsString应添加为邀请对象的电子邮件地址的列表(以英文逗号分隔)。
sendInvitesBoolean是否发送邀请电子邮件(默认值:false)。

弃踢回攻

CalendarEvent - 所创建的事件。

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

createAllDayEvent(title, date, options)

创建新的全天活动。

// Creates an all-day event for the moon landing and logs the ID.
var event = CalendarApp.getDefaultCalendar().createAllDayEvent('Apollo 11 Landing',
    new Date('July 20, 1969'),
    {location: 'The Moon'});
Logger.log('Event ID: ' + event.getId());

参数

名称类型说明
titleString活动的标题。
dateDate活动的日期(仅使用日期;忽略时间)。
optionsObject一个用于指定高级参数的 JavaScript 对象,如下所示。

高级参数

名称类型说明
descriptionString事件的说明。
locationString活动地点。
guestsString应添加为邀请对象的电子邮件地址的列表(以英文逗号分隔)。
sendInvitesBoolean是否发送邀请电子邮件(默认值:false)。

弃踢回攻

CalendarEvent - 所创建的事件。

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

createAllDayEventSeries(title, startDate, recurrence)

创建新的全天活动系列。

// Creates an event series for a no-meetings day, taking place every Wednesday in 2013.
var eventSeries = CalendarApp.getDefaultCalendar().createAllDayEventSeries('No Meetings',
    new Date('January 2, 2013 03:00:00 PM EST'),
    CalendarApp.newRecurrence().addWeeklyRule()
        .onlyOnWeekday(CalendarApp.Weekday.WEDNESDAY)
        .until(new Date('January 1, 2014')));
Logger.log('Event Series ID: ' + eventSeries.getId());

参数

名称类型说明
titleString系列中活动的标题
startDateDate系列中第一个活动的日期(仅使用日期;时间会被忽略)
recurrenceEventRecurrence活动系列的重复规则设置

弃踢回攻

CalendarEventSeries - 已创建的活动系列

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

createAllDayEventSeries(title, startDate, recurrence, options)

创建新的全天活动系列。

// Creates an event series for a no-meetings day, taking place every Wednesday in 2013.
var eventSeries = CalendarApp.getDefaultCalendar().createAllDayEventSeries('No Meetings',
    new Date('January 2, 2013 03:00:00 PM EST'),
    CalendarApp.newRecurrence().addWeeklyRule()
        .onlyOnWeekday(CalendarApp.Weekday.WEDNESDAY)
        .until(new Date('January 1, 2014')),
    {guests: 'everyone@example.com'});
Logger.log('Event Series ID: ' + eventSeries.getId());

参数

名称类型说明
titleString系列中活动的标题
startDateDate系列中第一个活动的日期(仅使用日期;时间会被忽略)
recurrenceEventRecurrence活动系列的重复规则设置
optionsObject一个用于指定高级参数的 JavaScript 对象,如下所示

高级参数

名称类型说明
descriptionString系列中活动的说明
locationString活动在系列中的地点
guestsString一系列电子邮件地址(应作为邀请对象添加到系列中的活动),以英文逗号分隔
sendInvitesBoolean是否发送电子邮件邀请(默认值:false

弃踢回攻

CalendarEventSeries - 已创建的活动系列

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

createEvent(title, startTime, endTime)

创建新的事件。

如果未指定时区,则根据脚本时区的上下文来解释时间值,该时区可能与日历的时区不同。

// Creates an event for the moon landing and logs the ID.
var event = CalendarApp.getDefaultCalendar().createEvent('Apollo 11 Landing',
    new Date('July 20, 1969 20:00:00 UTC'),
    new Date('July 21, 1969 21:00:00 UTC'));
Logger.log('Event ID: ' + event.getId());

参数

名称类型说明
titleString活动的标题
startTimeDate活动开始的日期和时间
endTimeDate活动结束的日期和时间

弃踢回攻

CalendarEvent - 创建的事件

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

createEvent(title, startTime, endTime, options)

创建新的事件。

如果未指定时区,则根据脚本时区的上下文来解释时间值,该时区可能与日历的时区不同。

// Creates an event for the moon landing and logs the ID.
var event = CalendarApp.getDefaultCalendar().createEvent('Apollo 11 Landing',
    new Date('July 20, 1969 20:00:00 UTC'),
    new Date('July 20, 1969 21:00:00 UTC'),
    {location: 'The Moon'});
Logger.log('Event ID: ' + event.getId());

参数

名称类型说明
titleString活动的标题
startTimeDate活动开始的日期和时间
endTimeDate活动结束的日期和时间
optionsObject一个用于指定高级参数的 JavaScript 对象,如下所示

高级参数

名称类型说明
descriptionString活动说明
locationString活动地点
guestsString应添加为邀请对象的电子邮件地址的逗号分隔列表
sendInvitesBoolean是否发送电子邮件邀请(默认值:false

弃踢回攻

CalendarEvent - 创建的事件

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

createEventFromDescription(description)

根据自由形式的说明创建事件。

说明的格式应与界面的“快速添加”功能相同。

// Creates a new event and logs its ID.
var event = CalendarApp.getDefaultCalendar()
    .createEventFromDescription('Lunch with Mary, Friday at 1PM');
Logger.log('Event ID: ' + event.getId());

参数

名称类型说明
descriptionString活动说明(形式不限)

弃踢回攻

CalendarEvent - 创建的事件

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

createEventSeries(title, startTime, endTime, recurrence)

创建新的活动系列。

// Creates an event series for a team meeting, taking place every Tuesday and Thursday in 2013.
var eventSeries = CalendarApp.getDefaultCalendar().createEventSeries('Team Meeting',
    new Date('January 1, 2013 03:00:00 PM EST'),
    new Date('January 1, 2013 04:00:00 PM EST'),
    CalendarApp.newRecurrence().addWeeklyRule()
        .onlyOnWeekdays([CalendarApp.Weekday.TUESDAY, CalendarApp.Weekday.THURSDAY])
        .until(new Date('January 1, 2014')));
Logger.log('Event Series ID: ' + eventSeries.getId());

参数

名称类型说明
titleString系列中活动的标题
startTimeDate系列中第一个活动开始的日期和时间
endTimeDate系列中第一个活动结束的日期和时间
recurrenceEventRecurrence活动系列的重复规则设置

弃踢回攻

CalendarEventSeries - 已创建的活动系列

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

createEventSeries(title, startTime, endTime, recurrence, options)

创建新的活动系列。

// Creates an event series for a team meeting, taking place every Tuesday and Thursday in 2013.
var eventSeries = CalendarApp.getDefaultCalendar().createEventSeries('Team Meeting',
    new Date('January 1, 2013 03:00:00 PM EST'),
    new Date('January 1, 2013 04:00:00 PM EST'),
    CalendarApp.newRecurrence().addWeeklyRule()
        .onlyOnWeekdays([CalendarApp.Weekday.TUESDAY, CalendarApp.Weekday.THURSDAY])
        .until(new Date('January 1, 2014')),
    {location: 'Conference Room'});
Logger.log('Event Series ID: ' + eventSeries.getId());

参数

名称类型说明
titleString系列中活动的标题
startTimeDate系列中第一个活动开始的日期和时间
endTimeDate系列中第一个活动结束的日期和时间
recurrenceEventRecurrence活动系列的重复规则设置
optionsObject一个用于指定高级参数的 JavaScript 对象,如下所示

高级参数

名称类型说明
descriptionString系列中活动的说明
locationString活动在系列中的地点
guestsString一系列电子邮件地址(应作为邀请对象添加到系列中的活动),以英文逗号分隔
sendInvitesBoolean是否发送电子邮件邀请(默认值:false

弃踢回攻

CalendarEventSeries - 已创建的活动系列

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

deleteCalendar()

永久删除日历。用户只能删除自己的日历。

// Creates a calendar to delete.
const calendar = CalendarApp.createCalendar('Test');

// Deletes the 'Test' calendar permanently.
calendar.deleteCalendar();

抛出

Error - 如果这是导入的日历。

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

getColor()

获取日历的颜色。

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('222larabrown@gmail.com');

// Gets the color of the calendar and logs it to the console.
// For the default calendar, you can use CalendarApp.getColor() instead.
const calendarColor = calendar.getColor();
console.log(calendarColor);

弃踢回攻

String - 十六进制颜色字符串(“#rrggbb”)。

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getDescription()

获取日历的说明。

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('222larabrown@gmail.com');

// Sets the description of the calendar to 'Test description.'
calendar.setDescription('Test description');

// Gets the description of the calendar and logs it to the console.
// For the default calendar, you can use CalendarApp.getDescription() instead.
const description = calendar.getDescription();
console.log(description);

弃踢回攻

String - 此日历的说明。

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getEventById(iCalId)

获取具有指定 ID 的事件。如果系列属于默认日历以外的日历,则必须从该日历调用此方法。调用 CalendarApp.getEventById(iCalId) 只会返回默认日历中的活动。

如果多个活动属于同一系列活动,那么这些活动可以具有相同的 ID。在这种情况下,此方法仅返回该系列中的第一个事件。

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('222larabrown@gmail.com')

// Creates an event for the moon landing.
const event = calendar.createEvent('Apollo 11 Landing',
  new Date('July 20, 1969 20:05:00 UTC'),
  new Date('July 20, 1969 20:17:00 UTC'));

// Gets the calendar event ID and logs it to the console.
const iCalId = event.getId();
console.log(iCalId);

// Gets the event by its ID and logs the title of the event to the console.
// For the default calendar, you can use CalendarApp.getEventById(iCalId) instead.
const myEvent = calendar.getEventById(iCalId);
console.log(myEvent.getTitle());

参数

名称类型说明
iCalIdString事件的 ID。

弃踢回攻

CalendarEvent - 具有指定 ID 的事件,如果事件不存在或用户无法访问,则为 null

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getEventSeriesById(iCalId)

获取具有指定 ID 的活动系列。如果给定的 ID 针对的是单个 CalendarEvent,系统会返回 CalendarEventSeries,其中包含系列中的单个事件。请注意,如果活动系列属于默认日历以外的日历,则必须从该 Calendar 调用此方法;直接调用 CalendarApp.getEventSeriesById(iCalId) 只会返回默认日历中存在的事件系列。

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('222larabrown@gmail.com');

// Creates an event series for a daily team meeting from 1 PM to 2 PM.
// The series adds the daily event from January 1, 2023 through December 31, 2023.
const eventSeries = calendar.createEventSeries('Team meeting',
  new Date('Jan 1, 2023 13:00:00'),
  new Date('Jan 1, 2023 14:00:00'),
  CalendarApp.newRecurrence().addDailyRule().until(new Date('Jan 1, 2024')));

// Gets the ID of the event series.
const iCalId = eventSeries.getId();

// Gets the event series by its ID and logs the series title to the console.
// For the default calendar, you can use CalendarApp.getEventSeriesById(iCalId) instead.
console.log(calendar.getEventSeriesById(iCalId).getTitle());

参数

名称类型说明
iCalIdString活动系列的 ID。

弃踢回攻

CalendarEventSeries - 具有指定 ID 的系列图书,如果系列不存在或用户无法访问,则为 null

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getEvents(startTime, endTime)

获取指定时间范围内发生的所有事件。

此方法会返回在给定时间范围内开始、在该时间范围内结束或者包含在该时间范围内的事件。如果未指定时区,系统会根据脚本的时区来解释时间值,该时区可能与日历的时区不同。

// Determines how many events are happening in the next two hours.
var now = new Date();
var twoHoursFromNow = new Date(now.getTime() + (2 * 60 * 60 * 1000));
var events = CalendarApp.getDefaultCalendar().getEvents(now, twoHoursFromNow);
Logger.log('Number of events: ' + events.length);

参数

名称类型说明
startTimeDate时间范围的开始时间
endTimeDate时间范围的结束时间(不含边界值)

弃踢回攻

CalendarEvent[] - 该时间范围内发生的事件

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getEvents(startTime, endTime, options)

获取指定时间范围内发生且符合指定条件的所有事件。

此方法会返回在给定时间范围内开始、在该时间范围内结束或者包含在该时间范围内的事件。如果未指定时区,系统会根据脚本的时区来解释时间值,该时区可能与日历的时区不同。

请注意,在应用 startmax 后,对 authorsearchstatusFilters 进行过滤。这意味着,即使有其他事件符合条件,返回的事件数可能少于 max

// Determines how many events are happening in the next two hours that contain the term
// "meeting".
var now = new Date();
var twoHoursFromNow = new Date(now.getTime() + (2 * 60 * 60 * 1000));
var events = CalendarApp.getDefaultCalendar().getEvents(now, twoHoursFromNow,
    {search: 'meeting'});
Logger.log('Number of events: ' + events.length);

参数

名称类型说明
startTimeDate时间范围的开始时间
endTimeDate时间范围的结束时间(不含边界值)
optionsObject一个用于指定高级参数的 JavaScript 对象,如下所示

高级参数

名称类型说明
startInteger要返回的第一个事件的索引
maxInteger要返回的事件数量上限
authorString用于按活动创建者过滤结果的电子邮件地址
searchString用于过滤结果的全文搜索查询
statusFilters[]GuestStatus用于过滤结果的状态数组

弃踢回攻

CalendarEvent[] - 在特定时间范围内发生的且符合条件的事件

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getEventsForDay(date)

获取指定日期发生的所有事件。

如果事件是在指定日期内开始、在当天结束或者包含这一天,此方法会返回这些事件。

请注意,仅使用 Date 对象的日期部分,并忽略时间部分。系统会将该日期解读为日历时区的相应日期午夜到次日午夜。

// Determines how many events are happening today.
var today = new Date();
var events = CalendarApp.getDefaultCalendar().getEventsForDay(today);
Logger.log('Number of events: ' + events.length);

参数

名称类型说明
dateDate要检索事件的日期(仅使用日期;忽略时间)

弃踢回攻

CalendarEvent[] - 在指定日期发生的事件

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getEventsForDay(date, options)

获取在指定日期发生且满足指定条件的所有事件。

如果事件是在指定日期内开始、在当天结束或者包含这一天,此方法会返回这些事件。

请注意,仅使用 Date 对象的日期部分,并忽略时间部分。系统会将该日期解读为日历时区的相应日期午夜到次日午夜。

请注意,在应用 startmax 后,对 authorsearchstatusFilters 进行过滤。这意味着,即使有其他事件符合条件,返回的事件数可能少于 max

// Determines how many events are happening today and contain the term "meeting".
var today = new Date();
var events = CalendarApp.getDefaultCalendar().getEventsForDay(today, {search: 'meeting'});
Logger.log('Number of events: ' + events.length);

参数

名称类型说明
dateDate要检索事件的日期(仅使用日期;忽略时间)
optionsObject高级过滤选项

高级参数

名称类型说明
startInteger要返回的第一个事件的索引
maxInteger要返回的事件数量上限
authorString用于按活动创建者过滤结果的电子邮件地址
searchString用于过滤结果的全文搜索查询
statusFilters[]GuestStatus用于过滤结果的状态数组

弃踢回攻

CalendarEvent[] - 在指定日期发生的符合条件的事件

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getId()

获取日历的 ID。用户的默认日历的 ID 就是他们的电子邮件地址。

// Opens the calendar by its ID.
// To get the user's default calendar, use CalendarApp.getDefaultCalendar().
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('222larabrown@gmail.com');

// Gets the ID of the calendar and logs it to the console.
const calendarId = calendar.getId();
console.log(calendarId);

弃踢回攻

String - 日历的 ID。

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getName()

获取日历的名称。

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('222larabrown@gmail.com');

// Gets the name of the calendar and logs it to the console.
// For the default calendar, you can use CalendarApp.getName() instead.
const calendarName = calendar.getName();
console.log(calendarName);

弃踢回攻

String - 此日历的名称。

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getTimeZone()

获取日历的时区。

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('222larabrown@gmail.com');

// Gets the time zone of the calendar and logs it to the console.
// For the default calendar, you can use CalendarApp.getTimeZone() instead.
const timeZone = calendar.getTimeZone();
console.log(timeZone);

弃踢回攻

String - 时区,以“long”格式指定(例如,“America/New_York”,由 Joda.org 列出)。

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

isHidden()

确定日历是否在界面中隐藏。

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('222larabrown@gmail.com');

// Determines whether the calendar is hidden in the user interface and logs it to the console.
// For the default calendar, you can use CalendarApp.isHidden() instead.
const isHidden = calendar.isHidden();
console.log(isHidden);

弃踢回攻

Boolean - 如果日历在界面中已隐藏,则为 true;如果日历未隐藏,则为 false

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

isMyPrimaryCalendar()

确定日历是否为有效用户的主日历。

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('222larabrown@gmail.com');

// Determines whether the calendar is the default calendar for
// the effective user and logs it to the console.
// For the default calendar, you can use CalendarApp.isMyPrimaryCalendar() instead.
const isMyPrimaryCalendar = calendar.isMyPrimaryCalendar();
console.log(isMyPrimaryCalendar);

弃踢回攻

Boolean - 如果日历是有效用户的默认日历,则为 true;如果不是有效用户的默认日历,则为 false

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

isOwnedByMe()

确定日历是否归您所有。

// Gets a calendar by its ID. To get the user's default calendar, use
// CalendarApp.getDefault() instead.
// TODO(developer): Replace the ID with the calendar ID that you want to use.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Determines whether the calendar is owned by you and logs it.
console.log(calendar.isOwnedByMe());

弃踢回攻

Boolean - 如果日历归您所有,则为 true;如果日历归您所有,则为 false

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

isSelected()

确定日历中是否显示日历的活动。

// Gets the user's default calendar. To get a different calendar, use getCalendarById()
// instead.
const calendar = CalendarApp.getDefaultCalendar();

// Determines whether the calendar's events are displayed in the user interface and logs it.
console.log(calendar.isSelected());

弃踢回攻

Boolean - 如果日历的活动显示在界面中,则为 true;如果未显示,则为 false

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

setColor(color)

设置日历的颜色。

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('222larabrown@gmail.com');

// Sets the color of the calendar to pink using the Calendar Color enum.
// For the default calendar, you can use CalendarApp.setColor() instead.
calendar.setColor(CalendarApp.Color.PINK);

参数

名称类型说明
colorStringCalendarApp.Color 或十六进制颜色字符串(“#rrggbb”)。

弃踢回攻

Calendar - 此日历用于串联。

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

setDescription(description)

设置日历的说明。

// Gets the user's default calendar. To get a different calendar, use getCalendarById()
// instead.
const calendar = CalendarApp.getDefaultCalendar();

// Sets the description of the calendar.
// TODO(developer): Update the string with the description that you want to use.
calendar.setDescription('Updated calendar description.')

参数

名称类型说明
descriptionString此日历的说明

弃踢回攻

Calendar - 此日历用于串联

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

setHidden(hidden)

设置是否在界面中显示日历。

参数

名称类型说明
hiddenBooleantrue 用于在界面中隐藏日历;false 可显示日历

弃踢回攻

Calendar - 此日历用于串联

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

setName(name)

设置日历的名称。

// Gets the user's default calendar. To get a different calendar, use getCalendarById()
// instead.
const calendar = CalendarApp.getDefaultCalendar();

// Sets the name of the calendar.
// TODO(developer): Update the string with the name that you want to use.
calendar.setName('Example calendar name');

参数

名称类型说明
nameString新名称

弃踢回攻

Calendar - 此日历用于串联

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

setSelected(selected)

设置是否在界面中显示日历的活动。

// Gets the user's default calendar. To get a different calendar, use getCalendarById()
// instead.
const calendar = CalendarApp.getDefaultCalendar();

// Selects the calendar so that its events are displayed in the user interface. To
// unselect the calendar, set the parameter to false.
calendar.setSelected(true);

参数

名称类型说明
selectedBooleantrue,用于在界面中显示日历的活动;false 可在界面中隐藏这些活动

弃踢回攻

Calendar - 此日历用于串联

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

setTimeZone(timeZone)

设置日历的时区。

// Gets the user's default calendar. To get a different calendar, use getCalendarById()
// instead.
const calendar = CalendarApp.getDefaultCalendar();

// Sets the time zone of the calendar to America/New York (US/Eastern) time.
calendar.setTimeZone('America/New_York');

参数

名称类型说明
timeZoneString时区,以“long”格式指定(例如“America/New_York”,由 Joda.org 列出)。

弃踢回攻

Calendar - 此日历用于串联。

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

unsubscribeFromCalendar()

为用户退订日历。用户无法退订我的日历列表下列出的日历。他们可以退订其他日历下列出的日历。

// Gets the calendar by its ID.
// TODO(developer): Replace the calendar ID with the calendar ID that you want to get.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Unsubscribes the user from the calendar.
const result = calendar.unsubscribeFromCalendar();

抛出

Error - 如果这是自有日历

授权

使用此方法的脚本需要获得以下一个或多个范围相关 REST API 的适当范围的授权:

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds