允许脚本读取和更新用户的 Google 日历。此类可让您直接访问用户的默认日历,并且能够检索用户拥有或订阅的其他日历。
属性
属性 | 类型 | 说明 |
---|---|---|
Color | Color | 表示日历服务中提供的已命名颜色的枚举。 |
EventColor | EventColor | 表示日历服务中提供的已命名活动颜色的枚举。 |
GuestStatus | GuestStatus | 表示来宾针对某个事件可以具有的状态的枚举。 |
Month | Month | 表示一年中的月份的枚举。 |
Visibility | Visibility | 表示事件可见性的枚举。 |
Weekday | Weekday | 表示一周中某天的枚举。 |
方法
详细文档
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());
参数
名称 | 类型 | 说明 |
---|---|---|
title | String | 活动的标题。 |
date | Date | 事件的日期(仅使用日期,忽略时间)。 |
弃踢回攻
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());
参数
名称 | 类型 | 说明 |
---|---|---|
title | String | 活动的标题。 |
startDate | Date | 活动的开始日期(仅使用日期,忽略时间)。 |
endDate | Date | 活动的结束日期(仅使用日期,忽略时间)。结束日期不计算在内。 |
弃踢回攻
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());
参数
名称 | 类型 | 说明 |
---|---|---|
title | String | 活动的标题。 |
startDate | Date | 活动的开始日期(仅使用日期,忽略时间)。 |
endDate | Date | 活动的结束日期(仅使用日期,忽略时间)。结束日期不计算在内。 |
options | Object | 一个用于指定高级参数的 JavaScript 对象,如下所示。 |
高级参数
名称 | 类型 | 说明 |
---|---|---|
description | String | 活动的说明。 |
location | String | 活动地点。 |
guests | String | 应添加为邀请对象的电子邮件地址列表(以英文逗号分隔)。 |
sendInvites | Boolean | 是否发送邀请电子邮件(默认值: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());
参数
名称 | 类型 | 说明 |
---|---|---|
title | String | 活动的标题。 |
date | Date | 事件的日期(仅使用日期,忽略时间)。 |
options | Object | 一个用于指定高级参数的 JavaScript 对象,如下所示。 |
高级参数
名称 | 类型 | 说明 |
---|---|---|
description | String | 活动的说明。 |
location | String | 活动地点。 |
guests | String | 应添加为邀请对象的电子邮件地址列表(以英文逗号分隔)。 |
sendInvites | Boolean | 是否发送邀请电子邮件(默认值: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());
参数
名称 | 类型 | 说明 |
---|---|---|
title | String | 系列中活动的标题 |
startDate | Date | 系列中第一个活动的日期(仅使用日期,时间会被忽略) |
recurrence | EventRecurrence | 活动系列的重复规则设置 |
弃踢回攻
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());
参数
名称 | 类型 | 说明 |
---|---|---|
title | String | 系列中活动的标题 |
startDate | Date | 系列中第一个活动的日期(仅使用日期,时间会被忽略) |
recurrence | EventRecurrence | 活动系列的重复规则设置 |
options | Object | 用于指定高级参数的 JavaScript 对象,如下所示 |
高级参数
名称 | 类型 | 说明 |
---|---|---|
description | String | 对该系列中活动的说明 |
location | String | 系列中活动的地点 |
guests | String | 应添加为系列活动的邀请对象的电子邮件地址列表(以英文逗号分隔) |
sendInvites | Boolean | 是否发送邀请电子邮件(默认值:false ) |
弃踢回攻
CalendarEventSeries
- 已创建的活动系列
授权
使用此方法的脚本需要以下一个或多个范围的授权,或者来自相关 REST API 的适当范围:
-
https://www.googleapis.com/auth/calendar
-
https://www.google.com/calendar/feeds
createCalendar(name)
创建归用户所有的新日历。
// Creates a new calendar named "Travel Plans". var calendar = CalendarApp.createCalendar('Travel Plans'); Logger.log('Created the calendar "%s", with the ID "%s".', calendar.getName(), calendar.getId());
参数
名称 | 类型 | 说明 |
---|---|---|
name | String | 新日历的名称 |
弃踢回攻
Calendar
- 新创建的日历
授权
使用此方法的脚本需要以下一个或多个范围的授权,或者来自相关 REST API 的适当范围:
-
https://www.googleapis.com/auth/calendar
-
https://www.google.com/calendar/feeds
createCalendar(name, options)
创建归用户所有的新日历。
// Creates a new calendar named "Travel Plans" with a summary and color. var calendar = CalendarApp.createCalendar('Travel Plans', { summary: 'A calendar to plan my travel schedule.', color: CalendarApp.Color.BLUE }); Logger.log('Created the calendar "%s", with the ID "%s".', calendar.getName(), calendar.getId());
参数
名称 | 类型 | 说明 |
---|---|---|
name | String | 新日历的名称 |
options | Object | 用于指定高级参数的 JavaScript 对象,如下所示 |
高级参数
名称 | 类型 | 说明 |
---|---|---|
location | String | 日历的位置 |
summary | String | 日历的说明 |
timeZone | String | 要为日历设置的时区,以“long”格式指定(例如,“America/New_York”,由 Joda.org 列出) |
color | String | 十六进制颜色字符串(“#rrggbb”)或 CalendarApp.Colors 中的值 |
hidden | Boolean | 日历是否隐藏在界面中(默认值:false ) |
selected | Boolean | 日历的活动是否显示在界面中(默认值:true ) |
弃踢回攻
Calendar
- 新创建的日历
授权
使用此方法的脚本需要以下一个或多个范围的授权,或者来自相关 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());
参数
名称 | 类型 | 说明 |
---|---|---|
title | String | 活动标题 |
startTime | Date | 活动开始的日期和时间 |
endTime | Date | 活动结束的日期和时间 |
弃踢回攻
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());
参数
名称 | 类型 | 说明 |
---|---|---|
title | String | 活动标题 |
startTime | Date | 活动开始的日期和时间 |
endTime | Date | 活动结束的日期和时间 |
options | Object | 用于指定高级参数的 JavaScript 对象,如下所示 |
高级参数
名称 | 类型 | 说明 |
---|---|---|
description | String | 活动说明 |
location | String | 活动地点 |
guests | String | 应添加为邀请对象的电子邮件地址列表(以英文逗号分隔) |
sendInvites | Boolean | 是否发送邀请电子邮件(默认值: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());
参数
名称 | 类型 | 说明 |
---|---|---|
description | String | 活动说明(不限形式) |
弃踢回攻
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());
参数
名称 | 类型 | 说明 |
---|---|---|
title | String | 系列中活动的标题 |
startTime | Date | 系列中第一个活动开始的日期和时间 |
endTime | Date | 系列中第一个活动的结束日期和时间 |
recurrence | EventRecurrence | 活动系列的重复规则设置 |
弃踢回攻
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());
参数
名称 | 类型 | 说明 |
---|---|---|
title | String | 系列中活动的标题 |
startTime | Date | 系列中第一个活动开始的日期和时间 |
endTime | Date | 系列中第一个活动的结束日期和时间 |
recurrence | EventRecurrence | 活动系列的重复规则设置 |
options | Object | 用于指定高级参数的 JavaScript 对象,如下所示 |
高级参数
名称 | 类型 | 说明 |
---|---|---|
description | String | 对该系列中活动的说明 |
location | String | 系列中活动的地点 |
guests | String | 应添加为系列活动的邀请对象的电子邮件地址列表(以英文逗号分隔) |
sendInvites | Boolean | 是否发送邀请电子邮件(默认值:false ) |
弃踢回攻
CalendarEventSeries
- 已创建的活动系列
授权
使用此方法的脚本需要以下一个或多个范围的授权,或者来自相关 REST API 的适当范围:
-
https://www.googleapis.com/auth/calendar
-
https://www.google.com/calendar/feeds
getAllCalendars()
获取用户拥有或订阅的所有日历。
// Determines how many calendars the user can access. var calendars = CalendarApp.getAllCalendars(); Logger.log('This user owns or is subscribed to %s calendars.', calendars.length);
弃踢回攻
Calendar[]
- 用户可以访问的所有日历
授权
使用此方法的脚本需要以下一个或多个范围的授权,或者来自相关 REST API 的适当范围:
-
https://www.googleapis.com/auth/calendar
-
https://www.googleapis.com/auth/calendar.readonly
-
https://www.google.com/calendar/feeds
getAllOwnedCalendars()
获取用户拥有的所有日历。
// Determines how many calendars the user owns. var calendars = CalendarApp.getAllOwnedCalendars(); Logger.log('This user owns %s calendars.', calendars.length);
弃踢回攻
Calendar[]
- 用户拥有的所有日历
授权
使用此方法的脚本需要以下一个或多个范围的授权,或者来自相关 REST API 的适当范围:
-
https://www.googleapis.com/auth/calendar
-
https://www.googleapis.com/auth/calendar.readonly
-
https://www.google.com/calendar/feeds
getCalendarById(id)
获取具有指定 ID 的日历。
// Gets the public calendar "US Holidays" by ID. var calendar = CalendarApp.getCalendarById( 'en.usa#holiday@group.v.calendar.google.com'); Logger.log('The calendar is named "%s".', calendar.getName());
参数
名称 | 类型 | 说明 |
---|---|---|
id | String | 日历 ID |
弃踢回攻
Calendar
- 具有指定 ID 的日历,如果日历不存在,用户无法访问,或者用户未订阅日历,则返回 null
授权
使用此方法的脚本需要以下一个或多个范围的授权,或者来自相关 REST API 的适当范围:
-
https://www.googleapis.com/auth/calendar
-
https://www.googleapis.com/auth/calendar.readonly
-
https://www.google.com/calendar/feeds
getCalendarsByName(name)
获取用户拥有或订阅的具有指定名称的所有日历。名称不区分大小写。
// Gets the public calendar named "US Holidays". var calendars = CalendarApp.getCalendarsByName('US Holidays'); Logger.log('Found %s matching calendars.', calendars.length);
参数
名称 | 类型 | 说明 |
---|---|---|
name | String | 日历名称 |
弃踢回攻
Calendar[]
- 用户可以访问的使用此名称的所有日历
授权
使用此方法的脚本需要以下一个或多个范围的授权,或者来自相关 REST API 的适当范围:
-
https://www.googleapis.com/auth/calendar
-
https://www.googleapis.com/auth/calendar.readonly
-
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
getDefaultCalendar()
获取用户的默认日历。
// Determines the time zone of the user's default calendar. var calendar = CalendarApp.getDefaultCalendar(); Logger.log('My default calendar is set to the time zone "%s".', calendar.getTimeZone());
弃踢回攻
Calendar
- 用户的默认日历
授权
使用此方法的脚本需要以下一个或多个范围的授权,或者来自相关 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 的事件。如果该系列属于默认日历以外的日历,则必须从该日历中调用此方法。调用 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());
参数
名称 | 类型 | 说明 |
---|---|---|
iCalId | String | 事件的 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
,以及系列中的单个事件。请注意,如果活动系列属于默认日历以外的日历,则必须从该 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());
参数
名称 | 类型 | 说明 |
---|---|---|
iCalId | String | 活动系列的 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);
参数
名称 | 类型 | 说明 |
---|---|---|
startTime | Date | 时间范围的开始时间 |
endTime | Date | 时间范围的结束日期(不含边界值) |
弃踢回攻
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)
获取指定时间范围内发生且满足指定条件的所有事件。
此方法会返回在给定时间范围内开始、在该时间范围内结束或者包含该时间范围的事件。如果未指定时区,则根据脚本的时区上下文解释时间值,该时区可能与日历的时区不同。
请注意,在应用 start
和 max
之后,对 author
、search
或 statusFilters
进行过滤。这意味着,即使有其他事件符合条件,返回的事件数可能少于 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);
参数
名称 | 类型 | 说明 |
---|---|---|
startTime | Date | 时间范围的开始时间 |
endTime | Date | 时间范围的结束日期(不含边界值) |
options | Object | 用于指定高级参数的 JavaScript 对象,如下所示 |
高级参数
名称 | 类型 | 说明 |
---|---|---|
start | Integer | 要返回的第一个事件的索引 |
max | Integer | 要返回的事件数量上限 |
author | String | 用于按活动创建者过滤结果的电子邮件地址 |
search | String | 用于过滤结果的全文搜索查询 |
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);
参数
名称 | 类型 | 说明 |
---|---|---|
date | Date | 检索事件的日期(仅使用日期,忽略时间) |
弃踢回攻
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 对象的日期部分,并忽略时间部分。系统将该日期解读为日历时区从当天午夜到次日午夜。
请注意,在应用 start
和 max
之后,对 author
、search
或 statusFilters
进行过滤。这意味着,即使有其他事件符合条件,返回的事件数可能少于 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);
参数
名称 | 类型 | 说明 |
---|---|---|
date | Date | 检索事件的日期(仅使用日期,忽略时间) |
options | Object | 高级过滤选项 |
高级参数
名称 | 类型 | 说明 |
---|---|---|
start | Integer | 要返回的第一个事件的索引 |
max | Integer | 要返回的事件数量上限 |
author | String | 用于按活动创建者过滤结果的电子邮件地址 |
search | String | 用于过滤结果的全文搜索查询 |
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
getOwnedCalendarById(id)
获取具有指定 ID 的日历(如果用户拥有该日历)。
如要查找日历 ID,请点击 Google 日历中日历名称旁边的箭头,然后选择日历设置。该 ID 显示在设置页面底部附近。
// Gets a (non-existent) private calendar by ID. var calendar = CalendarApp.getOwnedCalendarById( '123456789@group.calendar.google.com'); Logger.log('The calendar is named "%s".', calendar.getName());
参数
名称 | 类型 | 说明 |
---|---|---|
id | String | 日历 ID |
弃踢回攻
Calendar
- 具有指定 ID 的日历,如果日历不存在或用户不是该日历的所有者,则为 null
授权
使用此方法的脚本需要以下一个或多个范围的授权,或者来自相关 REST API 的适当范围:
-
https://www.googleapis.com/auth/calendar
-
https://www.googleapis.com/auth/calendar.readonly
-
https://www.google.com/calendar/feeds
getOwnedCalendarsByName(name)
获取用户拥有的具有指定名称的所有日历。名称不区分大小写。
// Gets a private calendar named "Travel Plans". var calendars = CalendarApp.getOwnedCalendarsByName('Travel Plans'); Logger.log('Found %s matching calendars.', calendars.length);
参数
名称 | 类型 | 说明 |
---|---|---|
name | String | 日历名称 |
弃踢回攻
Calendar[]
- 用户拥有的此名称的所有日历
授权
使用此方法的脚本需要以下一个或多个范围的授权,或者来自相关 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
newRecurrence()
创建一个新的重复周期对象,该对象可用于创建事件重复规则。
// Creates an event series for a no-meetings day, taking place every Wednesday in 2013. var recurrence = CalendarApp.newRecurrence().addWeeklyRule() .onlyOnWeekday(CalendarApp.Weekday.WEDNESDAY) .until(new Date('January 1, 2014')); var eventSeries = CalendarApp.getDefaultCalendar().createAllDayEventSeries('No Meetings', new Date('January 2, 2013 03:00:00 PM EST'), recurrence); Logger.log('Event Series ID: ' + eventSeries.getId());
弃踢回攻
EventRecurrence
- 未设置任何规则的新重复周期对象(表现为每周重复)
授权
使用此方法的脚本需要以下一个或多个范围的授权,或者来自相关 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);
参数
名称 | 类型 | 说明 |
---|---|---|
color | String | CalendarApp.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.')
参数
名称 | 类型 | 说明 |
---|---|---|
description | String | 此日历的说明 |
弃踢回攻
Calendar
- 此日历用于串联
授权
使用此方法的脚本需要以下一个或多个范围的授权,或者来自相关 REST API 的适当范围:
-
https://www.googleapis.com/auth/calendar
-
https://www.google.com/calendar/feeds
setHidden(hidden)
设置是否在界面中显示日历。
参数
名称 | 类型 | 说明 |
---|---|---|
hidden | Boolean | true 用于在界面中隐藏日历;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');
参数
名称 | 类型 | 说明 |
---|---|---|
name | String | 新名称 |
弃踢回攻
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);
参数
名称 | 类型 | 说明 |
---|---|---|
selected | Boolean | true ,用于在界面中显示日历的活动;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');
参数
名称 | 类型 | 说明 |
---|---|---|
timeZone | String | 时区,以“long”格式指定(例如“America/New_York”,如 Joda.org 所列)。 |
弃踢回攻
Calendar
- 此日历用于串联。
授权
使用此方法的脚本需要以下一个或多个范围的授权,或者来自相关 REST API 的适当范围:
-
https://www.googleapis.com/auth/calendar
-
https://www.google.com/calendar/feeds
subscribeToCalendar(id)
为用户订阅具有指定 ID 的日历(如果允许用户订阅)。
// Subscribe to the calendar "US Holidays". var calendar = CalendarApp.subscribeToCalendar( 'en.usa#holiday@group.v.calendar.google.com'); Logger.log('Subscribed to the calendar "%s".', calendar.getName());
参数
名称 | 类型 | 说明 |
---|---|---|
id | String | 要订阅的日历的 ID |
弃踢回攻
Calendar
- 新订阅的日历
抛出
Error
- 如果不存在具有此 ID 的日历
授权
使用此方法的脚本需要以下一个或多个范围的授权,或者来自相关 REST API 的适当范围:
-
https://www.googleapis.com/auth/calendar
-
https://www.google.com/calendar/feeds
subscribeToCalendar(id, options)
为用户订阅具有指定 ID 的日历(如果允许用户订阅)。
// Subscribe to the calendar "US Holidays", and set it to the color blue. var calendar = CalendarApp.subscribeToCalendar( 'en.usa#holiday@group.v.calendar.google.com', { color: CalendarApp.Color.BLUE }); Logger.log('Subscribed to the calendar "%s".', calendar.getName());
参数
名称 | 类型 | 说明 |
---|---|---|
id | String | 要订阅的日历的 ID。 |
options | Object | 一个用于指定高级参数的 JavaScript 对象,如下所示。 |
高级参数
名称 | 类型 | 说明 |
---|---|---|
color | String | 十六进制颜色字符串(“#rrggbb”)或 CalendarApp.Colors 中的值。 |
hidden | Boolean | 日历是否隐藏在界面中(默认值:false )。 |
selected | Boolean | 日历的活动是否显示在界面中(如果还指定了 color ,则默认值为 true ,否则为 false )。 |
弃踢回攻
Calendar
- 新订阅的日历。
抛出
Error
- 如果不存在具有此 ID 的日历
授权
使用此方法的脚本需要以下一个或多个范围的授权,或者来自相关 REST API 的适当范围:
-
https://www.googleapis.com/auth/calendar
-
https://www.google.com/calendar/feeds