Allows a script to read and update the user's Google Calendar. This class provides direct access to the user's default calendar, as well as the ability to retrieve additional calendars that the user owns or is subscribed to.
PropertyTypeDescription
Color
Color
An enum representing the named colors available in the Calendar service.
EventColor
EventColor
An enum representing the named event colors available in the Calendar service.
GuestStatus
GuestStatus
An enum representing the statuses a guest can have for an event.
Month
Month
An enum representing the months of the year.
Visibility
Visibility
An enum representing the visibility of an event.
Weekday
Weekday
An enum representing the days of the week.
MethodReturn typeBrief description
Creates a new all-day event.
Creates a new all-day event.
Creates a new all-day event.
Creates a new all-day event.
Creates a new all-day event series.
Creates a new all-day event series.
Creates a new calendar, owned by the user.
Creates a new calendar, owned by the user.
Creates a new event.
Creates a new event.
Creates an event from a free-form description.
Creates a new event series.
Creates a new event series.
Gets all calendars that the user owns or is subscribed to.
Gets all calendars that the user owns.
Gets the calendar with the given ID.
Gets all calendars with a given name that the user owns or is subscribed to.
getColor()
String
Gets the color of the calendar.
Gets the user's default calendar.
getDescription()
String
Gets the description of the calendar.
Gets the event with the given ID.
Gets the event series with the given ID.
Gets all events that occur within a given time range.
Gets all events that occur within a given time range and meet the specified criteria.
Gets all events that occur on a given day.
Gets all events that occur on a given day and meet specified criteria.
getId()
String
Gets the ID of the calendar.
getName()
String
Gets the name of the calendar.
Gets the calendar with the given ID, if the user owns it.
Gets all calendars with a given name that the user owns.
getTimeZone()
String
Gets the time zone of the calendar.
isHidden()
Boolean
Determines whether the calendar is hidden in the user interface.
isMyPrimaryCalendar()
Boolean
Determines whether the calendar is the default calendar for the effective user.
isOwnedByMe()
Boolean
Determines whether the calendar is owned by the effective user.
isSelected()
Boolean
Determines whether the calendar's events are displayed in the user interface.
Creates a new recurrence object, which can be used to create rules for event recurrence.
Sets the color of the calendar.
Sets the description of the calendar.
Sets whether the calendar is visible in the user interface.
Sets the name of the calendar.
Sets whether the calendar's events are displayed in the user interface.
Sets the time zone of the calendar.
Subscribes the user to the calendar with the given ID, if the user is allowed to subscribe.
Subscribes the user to the calendar with the given ID, if the user is allowed to subscribe.
Creates a new all-day event.
// 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());
Parameters
NameTypeDescription
title
String
the title of the event
date
Date
the date of the event (only the day is used; the time is ignored)
Return
CalendarEvent
— the created event
Creates a new all-day event.
// 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());
Parameters
NameTypeDescription
title
String
the title of the event
startDate
Date
the date when the event starts (only the day is used; the time is ignored)
endDate
Date
the date when the event ends (only the day is used; the time is ignored)
Return
CalendarEvent
— the created event
Creates a new all-day event.
// 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());
Parameters
NameTypeDescription
title
String
the title of the event
startDate
Date
the date when the event starts (only the day is used; the time is ignored)
endDate
Date
the date when the event ends (only the day is used; the time is ignored)
options
Object
a JavaScript object that specifies advanced parameters, as listed below
Advanced parameters
NameTypeDescription
description
String
the description of the event
location
String
the location of the event
guests
String
a comma-separated list of email addresses that should be added as guests
sendInvites
Boolean
whether to send invitation emails (default: false
)
Return
CalendarEvent
— the created event
Creates a new all-day event.
// 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());
Parameters
NameTypeDescription
title
String
the title of the event
date
Date
the date of the event (only the day is used; the time is ignored)
options
Object
a JavaScript object that specifies advanced parameters, as listed below
Advanced parameters
NameTypeDescription
description
String
the description of the event
location
String
the location of the event
guests
String
a comma-separated list of email addresses that should be added as guests
sendInvites
Boolean
whether to send invitation emails (default: false
)
Return
CalendarEvent
— the created event
Creates a new all-day event series.
// 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());
Parameters
NameTypeDescription
title
String
the title of the events in the series
startDate
Date
the date of the first event in the series (only the day is used; the time is ignored)
recurrence
EventRecurrence
the recurrence settings of the event series
Return
CalendarEventSeries
— the created event series
Creates a new all-day event series.
// 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());
Parameters
NameTypeDescription
title
String
the title of the events in the series
startDate
Date
the date of the first event in the series (only the day is used; the time is ignored)
recurrence
EventRecurrence
the recurrence settings of the event series
options
Object
a JavaScript object that specifies advanced parameters, as listed below
Advanced parameters
NameTypeDescription
description
String
the description of the events in the series
location
String
the location of the events in the series
guests
String
a comma-separated list of email addresses that should be added as guests to the events in the series
sendInvites
Boolean
whether to send invitation emails (default: false
)
Return
CalendarEventSeries
— the created event series
Creates a new calendar, owned by the user.
// 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());
Parameters
NameTypeDescription
name
String
the name of the new calendar
Return
Calendar
— the newly created calendar
Creates a new calendar, owned by the user.
// 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());
Parameters
NameTypeDescription
name
String
the name of the new calendar
options
Object
a JavaScript object that specifies advanced parameters, as listed below
Advanced parameters
NameTypeDescription
location
String
the calendar's location
summary
String
the calendar's description
timeZone
String
the time zone to set the calendar to, specified in "long" format (e.g., "America/New_York", as listed by Joda.org)
color
String
a hexadecimal color string ("#rrggbb") or a value from CalendarApp.Colors
hidden
Boolean
whether the calendar is hidden in the user interface (default: false
)
selected
Boolean
whether the calendar's events are displayed in the user interface (default: true
)
Return
Calendar
— the newly created calendar
Creates a new event.
If no time zone is specified, the time values are interpreted in the context of the script's time zone, which may be different than the calendar's time zone.
// 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());
Parameters
NameTypeDescription
title
String
the title of the event
startTime
Date
the date and time when the event starts
endTime
Date
the date and time when the event ends
Return
CalendarEvent
— the created event
Creates a new event.
If no time zone is specified, the time values are interpreted in the context of the script's time zone, which may be different than the calendar's time zone.
// 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());
Parameters
NameTypeDescription
title
String
the title of the event
startTime
Date
the date and time when the event starts
endTime
Date
the date and time when the event ends
options
Object
a JavaScript object that specifies advanced parameters, as listed below
Advanced parameters
NameTypeDescription
description
String
the description of the event
location
String
the location of the event
guests
String
a comma-separated list of email addresses that should be added as guests
sendInvites
Boolean
whether to send invitation emails (default: false
)
Return
CalendarEvent
— the created event
Creates an event from a free-form description.
The description should use the same format as the UI's "Quick Add" feature.
// 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());
Parameters
NameTypeDescription
description
String
a free-form description of the event
Return
CalendarEvent
— the created event
Creates a new event series.
// 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());
Parameters
NameTypeDescription
title
String
the title of the events in the series
startTime
Date
the date and time when the first event in the series starts
endTime
Date
the date and time when the first event in the series ends
recurrence
EventRecurrence
the recurrence settings of the event series
Return
CalendarEventSeries
— the created event series
Creates a new event series.
// 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());
Parameters
NameTypeDescription
title
String
the title of the events in the series
startTime
Date
the date and time when the first event in the series starts
endTime
Date
the date and time when the first event in the series ends
recurrence
EventRecurrence
the recurrence settings of the event series
options
Object
a JavaScript object that specifies advanced parameters, as listed below
Advanced parameters
NameTypeDescription
description
String
the description of the events in the series
location
String
the location of the events in the series
guests
String
a comma-separated list of email addresses that should be added as guests to the events in the series
sendInvites
Boolean
whether to send invitation emails (default: false
)
Return
CalendarEventSeries
— the created event series
Gets all calendars that the user owns or is subscribed to.
// 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);
Return
Calendar[]
— all calendars that the user can access
Gets all calendars that the user owns.
// Determines how many calendars the user owns.
var calendars = CalendarApp.getAllOwnedCalendars();
Logger.log('This user owns %s calendars.', calendars.length);
Return
Calendar[]
— all calendars that the user owns
Gets the calendar with the given 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());
Parameters
NameTypeDescription
id
String
the calendar ID
Return
Calendar
— the calendar with the given ID, or null
if the calendar does not exist or the user cannot access it
Gets all calendars with a given name that the user owns or is subscribed to. Names are not case-sensitive.
// Gets the public calendar named "US Holidays".
var calendars = CalendarApp.getCalendarsByName('US Holidays');
Logger.log('Found %s matching calendars.', calendars.length);
Parameters
NameTypeDescription
name
String
the calendar name
Return
Calendar[]
— all calendars with this name that the user can access
Gets the color of the calendar.
Return
String
— a hexadecimal color string ("#rrggbb")
Gets the user's default calendar.
// 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());
Return
Calendar
— the user's default calendar
Gets the description of the calendar.
Return
String
— the description of this calendar
Gets the event with the given ID. If the series belongs to a calendar other than the default calendar, this method must be called from that CalendarApp
. Calling getEventById(iCalId)
only returns an event in the default calendar.
Multiple events may have the same ID if they are part of an event series. In this case this method returns only the first event from that series.
Parameters
NameTypeDescription
iCalId
String
ID of the event
Return
CalendarEvent
— the event with the given ID, or null
if the event doesn't exist or the user cannot access it.
Gets the event series with the given ID. If the ID given is for a single CalendarEvent
, then a CalendarEventSeries
is returned with a single event in the series. Note that if the event series belongs to a calendar other than the default calendar, this method must be called from that CalendarApp
; calling getEventSeriesById(iCalId)
directly only returns an event series that exists in the default calendar.
Parameters
NameTypeDescription
iCalId
String
ID of the event series
Return
CalendarEventSeries
— the series with the given ID, or null
if the series doesn't exist or the user cannot access it
Gets all events that occur within a given time range.
This method returns events that start during the given time range, end during the time range, or encompass the time range. If no time zone is specified, the time values are interpreted in the context of the script's time zone, which may be different from the calendar's time zone.
// 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);
Parameters
NameTypeDescription
startTime
Date
the start of the time range
endTime
Date
the end of the time range, non-inclusive
Return
CalendarEvent[]
— the events that occur within the time range
Gets all events that occur within a given time range and meet the specified criteria.
This method returns events that start during the given time range, ends during the time range, or encompasses the time range. If no time zone is specified, the time values are interpreted in the context of the script's time zone, which may be different from the calendar's time zone.
Be aware that filtering on author
, search
, or statusFilters
takes place after applying start
and max
. This means that the number of events returned may be less than max
, even though additional events meet the criteria.
// 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);
Parameters
NameTypeDescription
startTime
Date
the start of the time range
endTime
Date
the end of the time range, non-inclusive
options
Object
a JavaScript object that specifies advanced parameters, as listed below
Advanced parameters
NameTypeDescription
start
Integer
the index of the first event to return
max
Integer
the maximum number of events to return
author
String
an email address used to filter results by the event creator
search
String
a full-text search query used to filter results
statusFilters[]
GuestStatus
an array of statuses used to filter results
Return
CalendarEvent[]
— the events that take place within the time range and match the criteria
Gets all events that occur on a given day.
This method returns events if they start during the given day, end during the day, or encompass the day.
Note that only the date portion of the Date object is used, and the time portion is ignored. The date is interpreted as midnight that day to midnight the next day in the calendar's time zone.
// Determines how many events are happening today.
var today = new Date();
var events = CalendarApp.getDefaultCalendar().getEventsForDay(today);
Logger.log('Number of events: ' + events.length);
Parameters
NameTypeDescription
date
Date
the date to retrieve events for (only the day is used; the time is ignored)
Return
CalendarEvent[]
— the events that occur on the given date
Gets all events that occur on a given day and meet specified criteria.
This method returns events if they start during the given day, end during the day, or encompass the day.
Note that only the date portion of the Date object is used, and the time portion is ignored. The date is interpreted as midnight that day to midnight the next day in the calendar's time zone.
Be aware that filtering on author
, search
, or statusFilters
takes place after applying start
and max
. This means that the number of events returned may be less than max
, even though additional events meet the criteria.
// 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);
Parameters
NameTypeDescription
date
Date
the date to retrieve events for (only the day is used; the time is ignored)
options
Object
advanced filtering options
Advanced parameters
NameTypeDescription
start
Integer
the index of the first event to return
max
Integer
the maximum number of events to return
author
String
an email address used to filter results by the event creator
search
String
a full-text search query used to filter results
statusFilters[]
GuestStatus
an array of statuses used to filter results
Return
CalendarEvent[]
— the events that occur on the given date and match the criteria
Gets the ID of the calendar. The ID for a user's default calendar is their email address.
Return
String
— the ID of the calendar
Gets the name of the calendar.
Return
String
— this calendar's name
Gets the calendar with the given ID, if the user owns it.
To find a calendar ID, click the arrow next to the calendar's name in Google Calendar and select Calendar settings. The ID is shown near the bottom of the settings page.
// 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());
Parameters
NameTypeDescription
id
String
the calendar id
Return
Calendar
— the calendar with the given ID, or null
if the calendar does not exist or the user does not own it
Gets all calendars with a given name that the user owns. Names are not case-sensitive.
// Gets a private calendar named "Travel Plans".
var calendars = CalendarApp.getOwnedCalendarsByName('Travel Plans');
Logger.log('Found %s matching calendars.', calendars.length);
Parameters
NameTypeDescription
name
String
the calendar name
Return
Calendar[]
— all calendars with this name that the user owns
Gets the time zone of the calendar.
Return
String
— the time zone, specified in "long" format (e.g., "America/New_York", as listed by Joda.org)
Determines whether the calendar is hidden in the user interface.
Return
Boolean
— true
if the calendar is hidden in the user interface; false
if not
Determines whether the calendar is the default calendar for the effective user.
Return
Boolean
— true
if the calendar is the default calendar for the effective user; false
if not
Determines whether the calendar is owned by the effective user.
Return
Boolean
— true
if the calendar is owned by the effective user; false
if not
Determines whether the calendar's events are displayed in the user interface.
Return
Boolean
— true
if the calendar's events are displayed in the user interface; false
if not
Creates a new recurrence object, which can be used to create rules for event recurrence.
// 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());
Return
EventRecurrence
— a new recurrence object with no rules set (behaves as a weekly recurrence)
Sets the color of the calendar.
Parameters
NameTypeDescription
color
String
a hexadecimal color string ("#rrggbb") or a value from CalendarApp.Colors
Return
Calendar
— this calendar for chaining
Sets the description of the calendar.
Parameters
NameTypeDescription
description
String
the description of this calendar
Return
Calendar
— this calendar for chaining
Sets whether the calendar is visible in the user interface.
Parameters
NameTypeDescription
hidden
Boolean
true
to hide the calendar in the user interface; false
to show it
Return
Calendar
— this calendar for chaining
Sets the name of the calendar.
Parameters
NameTypeDescription
name
String
the new name
Return
Calendar
— this calendar for chaining
Sets whether the calendar's events are displayed in the user interface.
Parameters
NameTypeDescription
selected
Boolean
true
to show the calendar's events in the user interface; false
to hide them
Return
Calendar
— this calendar for chaining
Sets the time zone of the calendar.
Parameters
NameTypeDescription
timeZone
String
the time zone, specified in "long" format (e.g., "America/New_York", as listed by Joda.org)
Return
Calendar
— this calendar for chaining
Subscribes the user to the calendar with the given ID, if the user is allowed to subscribe.
// 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());
Parameters
NameTypeDescription
id
String
the ID of the calendar to subscribe to
Return
Calendar
— the newly subscribed to calendar
Subscribes the user to the calendar with the given ID, if the user is allowed to subscribe.
// 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());
Parameters
NameTypeDescription
id
String
the ID of the calendar to subscribe to
options
Object
a JavaScript object that specifies advanced parameters, as listed below
Advanced parameters
NameTypeDescription
color
String
a hexadecimal color string ("#rrggbb") or a value from CalendarApp.Colors
hidden
Boolean
whether the calendar is hidden in the user interface (default: false
)
selected
Boolean
whether the calendar's events are displayed in the user interface (default: true
)
Return
Calendar
— the newly subscribed calendar
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License, and code samples are licensed under the Apache 2.0 License. For details, see our Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
最終更新日: 10月 20, 2017