メインコンテンツにスキップ

apps-script-samples

Apps Script samples for Google Workspace products.

AI Summary

Google Apps Script Samples

Provides concrete sample code for working with various Google APIs on Google Apps Script.

Target Users

Beginner to intermediate GAS developers who need to quickly learn Google API integration for internal tools or add-on development.

Problems Solved

Developers often lack concrete implementation examples for Google APIs with Apps Script beyond the official documentation.

Tags

Main Features

1
Wide Google API Coverage

Provides specific examples for major services such as Gmail, Calendar, and Sheets, enabling cross-service learning of API usage.

2
Ready-to-run Quickstarts

Contains numerous code snippets that run by simply pasting into the Apps Script editor, reducing setup overhead.

3
Templates & Codelabs for Guided Learning

Project templates and codelab-style tutorials help developers incrementally build implementation skills.

Usage Examples

Log the Next 10 Calendar Events

The snippet below, adapted from calendar/quickstart, shows how to call the Calendar API from Apps Script.

/**
 * Fetches and logs the next 10 events from the primary calendar.
 */
function listUpcomingEvents() {
  const calendarId = 'primary'; // Target calendar ID
  const now = new Date();

  // Call the Advanced Calendar Service
  const response = Calendar.Events.list(calendarId, {
    timeMin: now.toISOString(), // From now onward
    maxResults: 10,
    singleEvents: true,
    orderBy: 'startTime'
  });

  const events = response.items || [];
  if (events.length === 0) {
    Logger.log('No upcoming events found.');
    return;
  }

  // Log each event's title and start time
  events.forEach(event => {
    const start = event.start.dateTime || event.start.date;
    Logger.log('%s (%s)', event.summary, start);
  });
}

Paste this into the Apps Script editor, enable the "Calendar API" under Resources → Advanced Google services, and run the function to see event details in the log.