Class CalendarApp

CalendarApp

ユーザーの Google カレンダーの読み取りと更新をスクリプトに許可します。このクラスを使用すると、ユーザーのデフォルト カレンダーに直接アクセスできるだけでなく、ユーザーが所有または登録している追加のカレンダーを取得できます。

プロパティ

プロパティタイプ説明
ColorColorカレンダー サービスで使用可能な名前付きの色を表す列挙型。
EventColorEventColorカレンダー サービスで使用可能な名前付き予定の色を表す列挙型。
GuestStatusGuestStatusイベントでゲストに付与できるステータスを表す列挙型。
MonthMonth月を表す列挙型。
VisibilityVisibilityイベントの表示状態を表す列挙型。
WeekdayWeekday曜日を表す列挙型。

メソッド

メソッド戻り値の型概要
createAllDayEvent(title, date)CalendarEvent新しい終日の予定を作成します。
createAllDayEvent(title, startDate, endDate)CalendarEvent複数日にわたる新しい終日の予定を作成します。
createAllDayEvent(title, startDate, endDate, options)CalendarEvent複数日にわたる新しい終日の予定を作成します。
createAllDayEvent(title, date, options)CalendarEvent新しい終日の予定を作成します。
createAllDayEventSeries(title, startDate, recurrence)CalendarEventSeries新しい終日の予定を作成します。
createAllDayEventSeries(title, startDate, recurrence, options)CalendarEventSeries新しい終日の予定を作成します。
createCalendar(name)Calendarユーザーが所有する新しいカレンダーを作成します。
createCalendar(name, options)Calendarユーザーが所有する新しいカレンダーを作成します。
createEvent(title, startTime, endTime)CalendarEvent新しいイベントを作成します。
createEvent(title, startTime, endTime, options)CalendarEvent新しいイベントを作成します。
createEventFromDescription(description)CalendarEvent自由形式の説明からイベントを作成します。
createEventSeries(title, startTime, endTime, recurrence)CalendarEventSeries新しいイベント シリーズを作成します。
createEventSeries(title, startTime, endTime, recurrence, options)CalendarEventSeries新しいイベント シリーズを作成します。
getAllCalendars()Calendar[]ユーザーが所有または登録しているすべてのカレンダーを取得します。
getAllOwnedCalendars()Calendar[]ユーザーが所有するすべてのカレンダーを取得します。
getCalendarById(id)Calendar指定された ID のカレンダーを取得します。
getCalendarsByName(name)Calendar[]ユーザーが所有または登録している特定の名前を持つすべてのカレンダーを取得します。
getColor()Stringカレンダーの色を取得します。
getDefaultCalendar()Calendarユーザーのデフォルトのカレンダーを取得します。
getDescription()Stringカレンダーの説明を取得します。
getEventById(iCalId)CalendarEvent指定された ID のイベントを取得します。
getEventSeriesById(iCalId)CalendarEventSeries指定された ID のイベント シリーズを取得します。
getEvents(startTime, endTime)CalendarEvent[]指定された期間に発生したすべてのイベントを取得します。
getEvents(startTime, endTime, options)CalendarEvent[]特定の期間内に発生し、指定された条件を満たすすべてのイベントを取得します。
getEventsForDay(date)CalendarEvent[]指定された日で発生するすべてのイベントを取得します。
getEventsForDay(date, options)CalendarEvent[]特定の日に発生し、指定された条件を満たすすべてのイベントを取得します。
getId()Stringカレンダーの ID を取得します。
getName()Stringカレンダーの名前を取得します。
getOwnedCalendarById(id)Calendarユーザーがオーナーである場合、指定された ID のカレンダーを取得します。
getOwnedCalendarsByName(name)Calendar[]ユーザーが所有する特定の名前を持つすべてのカレンダーを取得します。
getTimeZone()Stringカレンダーのタイムゾーンを取得します。
isHidden()Booleanユーザー インターフェースでカレンダーを非表示にするかどうかを指定します。
isMyPrimaryCalendar()Booleanカレンダーを有効なユーザーのメイン カレンダーにするかどうかを決定します。
isOwnedByMe()Boolean自分がそのカレンダーのオーナーかどうかを判断します。
isSelected()Booleanカレンダーの予定をユーザー インターフェースに表示するかどうかを決定します。
newRecurrence()EventRecurrence新しい繰り返しオブジェクトを作成します。このオブジェクトを使用して、予定の繰り返しに関するルールを作成できます。
setColor(color)Calendarカレンダーの色を設定します。
setDescription(description)Calendarカレンダーの説明を設定します。
setHidden(hidden)Calendarカレンダーをユーザー インターフェースに表示するかどうかを設定します。
setName(name)Calendarカレンダーの名前を設定します。
setSelected(selected)Calendarカレンダーの予定をユーザー インターフェースに表示するかどうかを設定します。
setTimeZone(timeZone)Calendarカレンダーのタイムゾーンを設定します。
subscribeToCalendar(id)Calendar指定された ID でカレンダーに登録します(登録が許可されている場合)。
subscribeToCalendar(id, options)Calendar指定された ID でカレンダーに登録します(登録が許可されている場合)。

詳細なドキュメント

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());

パラメータ

名前説明
titleStringイベントのタイトル。
dateDateイベントの日付(日付のみが使用され、時刻は無視されます)。

リターン

CalendarEvent - 作成されたイベント。

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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());

パラメータ

名前説明
titleStringイベントのタイトル。
startDateDateイベントの開始日(日付のみが使用され、時刻は無視されます)。
endDateDateイベントの終了日(日付のみが使用され、時刻は無視されます)。終了日は含まれません。

リターン

CalendarEvent - 作成されたイベント。

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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());

パラメータ

名前説明
titleStringイベントのタイトル。
startDateDateイベントの開始日(日付のみが使用され、時刻は無視されます)。
endDateDateイベントの終了日(日付のみが使用され、時刻は無視されます)。終了日は含まれません。
optionsObject詳細パラメータを指定する JavaScript オブジェクト。下記をご覧ください。

拡張パラメータ

名前説明
descriptionStringイベントの説明。
locationStringイベントの場所。
guestsStringゲストとして追加するメールアドレスのカンマ区切りのリスト。
sendInvitesBoolean招待メールを送信するかどうか(デフォルト: false)。

リターン

CalendarEvent - 作成されたイベント。

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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());

パラメータ

名前説明
titleStringイベントのタイトル。
dateDateイベントの日付(日付のみが使用され、時刻は無視されます)。
optionsObject詳細パラメータを指定する JavaScript オブジェクト。下記をご覧ください。

拡張パラメータ

名前説明
descriptionStringイベントの説明。
locationStringイベントの場所。
guestsStringゲストとして追加するメールアドレスのカンマ区切りのリスト。
sendInvitesBoolean招待メールを送信するかどうか(デフォルト: false)。

リターン

CalendarEvent - 作成されたイベント。

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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());

パラメータ

名前説明
titleString一連の定期的な予定のタイトル
startDateDate一連の繰り返しの最初のイベントの日付(日付のみが使用され、時刻は無視されます)
recurrenceEventRecurrence一連の定期的な予定の繰り返し設定

リターン

CalendarEventSeries - 作成された一連のイベント

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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());

パラメータ

名前説明
titleString一連の定期的な予定のタイトル
startDateDate一連の繰り返しの最初のイベントの日付(日付のみが使用され、時刻は無視されます)
recurrenceEventRecurrence一連の定期的な予定の繰り返し設定
optionsObject詳細パラメータを指定する JavaScript オブジェクト

拡張パラメータ

名前説明
descriptionString一連のイベントの説明
locationString一連のイベントの場所
guestsString一連のイベントにゲストとして追加するメールアドレスのカンマ区切りのリスト
sendInvitesBoolean招待メールを送信するかどうか(デフォルト: false

リターン

CalendarEventSeries - 作成された一連のイベント

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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());

パラメータ

名前説明
nameString新しいカレンダーの名前

リターン

Calendar - 新しく作成されたカレンダー

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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());

パラメータ

名前説明
nameString新しいカレンダーの名前
optionsObject詳細パラメータを指定する JavaScript オブジェクト

拡張パラメータ

名前説明
locationStringカレンダーの場所
summaryStringカレンダーの説明
timeZoneStringカレンダーを設定するタイムゾーン。「long」形式で指定します(例:「America/New_York」、Joda.org によりリストされている)
colorString16 進数の色文字列(「#rrggbb」)または CalendarApp.Colors の値
hiddenBooleanユーザー インターフェースでカレンダーが非表示かどうか(デフォルト: false
selectedBooleanカレンダーの予定をユーザー インターフェースに表示するかどうか(デフォルト: true

リターン

Calendar - 新しく作成されたカレンダー

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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());

パラメータ

名前説明
titleString予定のタイトル
startTimeDateイベントの開始日時
endTimeDate予定の終了日時

リターン

CalendarEvent - 作成されたイベント

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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());

パラメータ

名前説明
titleString予定のタイトル
startTimeDateイベントの開始日時
endTimeDate予定の終了日時
optionsObject詳細パラメータを指定する JavaScript オブジェクト

拡張パラメータ

名前説明
descriptionStringイベントの説明
locationStringイベントの場所
guestsStringゲストとして追加するメールアドレスのカンマ区切りのリスト
sendInvitesBoolean招待メールを送信するかどうか(デフォルト: false

リターン

CalendarEvent - 作成されたイベント

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する REST API からの適切なスコープが必要です。

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

createEventFromDescription(description)

自由形式の説明からイベントを作成します。

説明には、UI の「クイック追加」機能と同じ形式を使用する必要があります。

// 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());

パラメータ

名前説明
descriptionStringイベントの説明(自由形式)

リターン

CalendarEvent - 作成されたイベント

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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());

パラメータ

名前説明
titleString一連の定期的な予定のタイトル
startTimeDate一連の定期的な予定の最初の予定の開始日時
endTimeDate一連の定期的な予定の最初の予定の終了日時
recurrenceEventRecurrence一連の定期的な予定の繰り返し設定

リターン

CalendarEventSeries - 作成された一連のイベント

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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());

パラメータ

名前説明
titleString一連の定期的な予定のタイトル
startTimeDate一連の定期的な予定の最初の予定の開始日時
endTimeDate一連の定期的な予定の最初の予定の終了日時
recurrenceEventRecurrence一連の定期的な予定の繰り返し設定
optionsObject詳細パラメータを指定する JavaScript オブジェクト

拡張パラメータ

名前説明
descriptionString一連のイベントの説明
locationString一連のイベントの場所
guestsString一連のイベントにゲストとして追加するメールアドレスのカンマ区切りのリスト
sendInvitesBoolean招待メールを送信するかどうか(デフォルト: false

リターン

CalendarEventSeries - 作成された一連のイベント

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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[] - ユーザーがアクセスできるすべてのカレンダー

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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[] - ユーザーが所有するすべてのカレンダー

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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());

パラメータ

名前説明
idStringカレンダー ID

リターン

Calendar - 指定された ID を持つカレンダー。カレンダーが存在しない場合、ユーザーがアクセスできない場合、またはユーザーがカレンダーに登録していない場合は null

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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);

パラメータ

名前説明
nameStringカレンダー名

リターン

Calendar[] - この名前でユーザーがアクセスできるすべてのカレンダー

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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 - 16 進数の色文字列(「#rrggbb」)。

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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 - ユーザーのデフォルトのカレンダー

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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 - このカレンダーの説明。

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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());

パラメータ

名前説明
iCalIdStringイベントの ID。

リターン

CalendarEvent - 指定された ID を持つイベント。イベントが存在しない場合、またはユーザーがイベントにアクセスできない場合は、null

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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 に対するものである場合、一連の中の 1 つのイベントとともに 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());

パラメータ

名前説明
iCalIdStringイベント シリーズの ID。

リターン

CalendarEventSeries - 指定された ID を持つシリーズ。シリーズが存在しないかユーザーがアクセスできない場合は null

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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);

パラメータ

名前説明
startTimeDate期間の開始時
endTimeDate期間の終了値(この値を含まない)

リターン

CalendarEvent[] - 期間内に発生したイベント

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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)

特定の期間内に発生し、指定された条件を満たすすべてのイベントを取得します。

このメソッドは、指定された期間内に開始されたイベント、指定された期間内に終了するイベント、または特定の期間を含むイベントを返します。タイムゾーンが指定されていない場合、時刻の値はスクリプトのタイムゾーンのコンテキストで解釈されます。これは、カレンダーのタイムゾーンとは異なる場合があります。

authorsearchstatusFilters でのフィルタリングは、startmax を適用した後に実行されることに注意してください。つまり、他のイベントが条件を満たしていても、返されるイベントの数が 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);

パラメータ

名前説明
startTimeDate期間の開始時
endTimeDate期間の終了値(この値を含まない)
optionsObject詳細パラメータを指定する JavaScript オブジェクト

拡張パラメータ

名前説明
startInteger返される最初のイベントのインデックス
maxInteger返されるイベントの最大数
authorStringイベント作成者による結果のフィルタリングに使用するメールアドレス
searchString検索結果のフィルタリングに使用する全文検索クエリ
statusFilters[]GuestStatus結果のフィルタリングに使用するステータスの配列

リターン

CalendarEvent[] - 期間内に発生し、条件に一致するイベント

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する REST API からの適切なスコープが必要です。

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getEventsForDay(date)

特定の日で発生するすべてのイベントを取得します。

このメソッドは、指定した日中に開始されるか、その日中に終了するか、または日を包含するイベントを返します。

Date オブジェクトの日付部分のみが使用され、時間部分は無視されます。 日付は、カレンダーのタイムゾーンで、その日の深夜 0 時から翌日の深夜 0 時までと解釈されます。

// Determines how many events are happening today.
var today = new Date();
var events = CalendarApp.getDefaultCalendar().getEventsForDay(today);
Logger.log('Number of events: ' + events.length);

パラメータ

名前説明
dateDateイベントを取得する日付(日付のみが使用され、時間は無視されます)

リターン

CalendarEvent[] - 指定された日付で発生するイベント

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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 オブジェクトの日付部分のみが使用され、時間部分は無視されます。 日付は、カレンダーのタイムゾーンで、その日の深夜 0 時から翌日の深夜 0 時までと解釈されます。

authorsearchstatusFilters でのフィルタリングは、startmax を適用した後に実行されることに注意してください。つまり、他のイベントが条件を満たしていても、返されるイベントの数が 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);

パラメータ

名前説明
dateDateイベントを取得する日付(日付のみが使用され、時間は無視されます)
optionsObject高度なフィルタ オプション

拡張パラメータ

名前説明
startInteger返される最初のイベントのインデックス
maxInteger返されるイベントの最大数
authorStringイベント作成者による結果のフィルタリングに使用するメールアドレス
searchString検索結果のフィルタリングに使用する全文検索クエリ
statusFilters[]GuestStatus結果のフィルタリングに使用するステータスの配列

リターン

CalendarEvent[] - 指定された日に発生した、条件に一致するイベント

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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。

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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 - このカレンダーの名前。

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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());

パラメータ

名前説明
idStringカレンダー ID

リターン

Calendar - 指定された ID のカレンダー。カレンダーが存在しない場合やユーザーがカレンダーを所有していない場合は null

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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);

パラメータ

名前説明
nameStringカレンダー名

リターン

Calendar[] - ユーザーが所有するこの名前を持つすべてのカレンダー

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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」形式で指定されたタイムゾーン(たとえば、Joda.org に記載されている「America/New_York」)。

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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 です。

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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 - ルールが設定されていない新しい繰り返しオブジェクト(毎週の繰り返しとして動作します)。

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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);

パラメータ

名前説明
colorStringCalendarApp.Color または 16 進数の色文字列(「#rrggbb」)。

リターン

Calendar - チェーン用のカレンダー。

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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.')

パラメータ

名前説明
descriptionStringこのカレンダーの説明

リターン

Calendar - チェーン用のこのカレンダー

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する REST API からの適切なスコープが必要です。

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

setHidden(hidden)

カレンダーをユーザー インターフェースに表示するかどうかを設定します。

パラメータ

名前説明
hiddenBooleantrue: ユーザー インターフェースのカレンダーを非表示にします。false: 表示します。

リターン

Calendar - チェーン用のこのカレンダー

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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');

パラメータ

名前説明
nameString新しい名前

リターン

Calendar - チェーン用のこのカレンダー

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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);

パラメータ

名前説明
selectedBooleantrue: ユーザー インターフェースにカレンダーの予定を表示します。false: 非表示にします

リターン

Calendar - チェーン用のこのカレンダー

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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');

パラメータ

名前説明
timeZoneString「long」形式で指定されたタイムゾーン(Joda.org でリストされている「America/New_York」など)。

リターン

Calendar - チェーン用のカレンダー。

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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());

パラメータ

名前説明
idString登録するカレンダーの ID

リターン

Calendar - 新しく登録したカレンダー

例外

Error - この ID のカレンダーが存在しない場合

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する 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());

パラメータ

名前説明
idString登録するカレンダーの ID。
optionsObject詳細パラメータを指定する JavaScript オブジェクト。下記をご覧ください。

拡張パラメータ

名前説明
colorString16 進数の色文字列(「#rrggbb」)または CalendarApp.Colors の値。
hiddenBooleanユーザー インターフェースでカレンダーを非表示にするかどうか(デフォルト: false)。
selectedBooleanカレンダーの予定をユーザー インターフェースに表示するかどうか(デフォルト: color も指定されている場合は true、それ以外の場合は false)。

リターン

Calendar - 新しく登録したカレンダー。

例外

Error - この ID のカレンダーが存在しない場合

認可

このメソッドを使用するスクリプトには、次のスコープのうち 1 つ以上による承認、または関連する REST API からの適切なスコープが必要です。

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds