Skip to content

Instantly share code, notes, and snippets.

@craigtommola
Last active February 26, 2018 19:47
Show Gist options
  • Save craigtommola/0ff3ac7ce0fd4a7f734811185313f82a to your computer and use it in GitHub Desktop.
Save craigtommola/0ff3ac7ce0fd4a7f734811185313f82a to your computer and use it in GitHub Desktop.
Quickstart: GAS Calendar - US Holidays
function doGet() {
var calendarId = 'en.usa#[email protected]'; // Public calendar we're connecting to
var optionalArgs = { // See optionalArgs at http://bit.ly/GAScal_eventlist
timeMin: (new Date()).toISOString(), // Setting today as the minimal time requirement
showDeleted: false, // Only show active events
singleEvents: true, // Return recurring events as individual events
maxResults: 10, // Max of 10 records
orderBy: 'startTime' // Order chronologically
};
var response = Calendar.Events.list(calendarId, optionalArgs); // Get the calendar content, based on parameters
var events = response.items; // Set variable "events" equal to items returned in previous line
if (events.length > 0) { // If there are more than zero events
for (i = 0; i < events.length; i++) { // For each of the events returned,
var event = events[i]; // Run through loop of events
var when = event.start.dateTime; // Set variable "when" equal to the start.dateTime value
if (!when) {
when = event.start.date; // If when is empty, set it equal to start.date - this is when an event is marked as "all day"
}
Logger.log('%s (%s)', event.summary, when); // Output "event name (and date)"
}
// return ContentService.createTextOutput(events).setMimeType(ContentService.MimeType.TEXT);
} else {
Logger.log('No upcoming events found.'); // If there are no events, show this message in the log
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment