The advanced Calendar service allows you to use the public Google Calendar API in Apps Script. Much like Apps Script's built-in Calendar service, this API allows scripts to access and modify the user's Google Calendar, including additional calendars that the user is subscribed to. In most cases, the built-in service is easier to use, but this advanced service provides a few extra features, including setting the background color for individual events.
Reference
For detailed information on this service, see the reference documentation for the public Google Calendar API. Like all advanced services in Apps Script, the advanced Calendar service uses the same objects, methods, and parameters as the public API. For more information, see How method signatures are determined.
To report issues and find other support, see the Calendar support guide.
HTTP request headers
The advanced Calendar service can accept the HTTP request headers
If-Match
and If-None-Match
. For details, see the
reference documentation.
Sample code
The sample code below uses version 3 of the API.
Creating events
The following example demonstrates how to create an event in the user's default calendar.
Listing calendars
The following example demonstrates how to retrieve details about the calendars shown in the user's calendar list.
Listing events
The following example demonstrates how to list the next 10 upcoming events in the user's default calendar.
Conditionally modifying an event
The following example shows how to conditionally update a Calendar event using
the If-Match
header. The script creates a new event, waits 30 seconds, then
updates the event only if no event details have changed since the event was
created.
Conditionally retrieving an event
The following example shows how to conditionally fetch a Calendar event using
the If-None-Match
header. The script creates a new event, then polls the
event for changes for 30 seconds. Any time the event changes, the new version
is fetched.
Synchronizing events
The following example demonstrates how to retrieve events using sync tokens. When you include a sync token in a Calendar advanced service request, the resulting response only includes items that have changed since that token was generated, enabling more efficient processing. See Synchronize Resources Efficiently for more details on the syncing process.
The following example makes use of the same getRelativeDate(daysOffset, hour)
method defined in the above examples.