Class CalendarEvent

CalendarEvent

代表單一日曆活動。

方法

方法傳回類型簡短說明
addEmailReminder(minutesBefore)CalendarEvent新增活動電子郵件提醒。
addGuest(email)CalendarEvent將邀請對象加入活動中。
addPopupReminder(minutesBefore)CalendarEvent將新的彈出式通知新增至事件。
addSmsReminder(minutesBefore)CalendarEvent新增活動簡訊提醒。
anyoneCanAddSelf()Boolean決定使用者是否能將自己新增為日曆活動的邀請對象。
deleteEvent()void刪除日曆活動。
deleteTag(key)CalendarEvent從事件中刪除鍵/值代碼。
getAllDayEndDate()Date取得這項全天日曆活動的結束日期。
getAllDayStartDate()Date取得這項全天日曆活動的開始日期。
getAllTagKeys()String[]取得已在事件上設定的所有代碼鍵。
getColor()String傳回日曆活動的顏色。
getCreators()String[]取得活動建立者。
getDateCreated()Date取得事件的建立日期。
getDescription()String取得活動說明。
getEmailReminders()Integer[]取得活動所有電子郵件提醒的分鐘數值。
getEndTime()Date取得這項日曆活動的結束日期和時間。
getEventSeries()CalendarEventSeries取得此活動所屬的一系列週期性活動。
getGuestByEmail(email)EventGuest取得邀請對象的電子郵件地址。
getGuestList()EventGuest[]取得活動邀請對象,包括活動擁有者。
getGuestList(includeOwner)EventGuest[]取得活動邀請對象,包括活動擁有者。
getId()String取得事件的專屬 iCalUID。
getLastUpdated()Date取得活動上次更新日期。
getLocation()String取得活動的位置。
getMyStatus()GuestStatus取得有效使用者的活動狀態 (例如參加或已邀請)。
getOriginalCalendarId()String取得建立這個活動時所在的日曆 ID。
getPopupReminders()Integer[]取得活動的所有彈出式提醒的分鐘數值。
getSmsReminders()Integer[]取得活動所有簡訊提醒的分鐘數值。
getStartTime()Date取得這個日曆活動的開始日期和時間。
getTag(key)String取得事件的代碼值。
getTitle()String取得活動名稱。
getVisibility()Visibility取得活動的瀏覽權限。
guestsCanInviteOthers()Boolean決定邀請對像是否能邀請其他邀請對象。
guestsCanModify()Boolean決定邀請對像是否可以修改活動。
guestsCanSeeGuests()Boolean決定邀請對像是否能看見其他邀請對象。
isAllDayEvent()Boolean判斷這是否為全天活動。
isOwnedByMe()Boolean判斷你是否為活動擁有者。
isRecurringEvent()Boolean判斷該活動是否屬於活動系列。
removeAllReminders()CalendarEvent用於移除活動的所有提醒。
removeGuest(email)CalendarEvent將邀請對象從活動中移除。
resetRemindersToDefault()CalendarEvent使用日曆的預設設定重設提醒。
setAllDayDate(date)CalendarEvent設定活動日期。
setAllDayDates(startDate, endDate)CalendarEvent設定活動日期。
setAnyoneCanAddSelf(anyoneCanAddSelf)CalendarEvent設定非邀請對像是否能將自己加入活動。
setColor(color)CalendarEvent設定日曆活動的顏色。
setDescription(description)CalendarEvent設定事件的說明。
setGuestsCanInviteOthers(guestsCanInviteOthers)CalendarEvent設定邀請對像是否可以邀請其他邀請對象。
setGuestsCanModify(guestsCanModify)CalendarEvent設定邀請對像是否可以修改活動。
setGuestsCanSeeGuests(guestsCanSeeGuests)CalendarEvent設定邀請對像是否能看到其他邀請對象。
setLocation(location)CalendarEvent設定事件的地點。
setMyStatus(status)CalendarEvent設定有效使用者的活動狀態,例如參加或已邀請。
setTag(key, value)CalendarEvent設定事件的鍵/值標記來儲存自訂中繼資料。
setTime(startTime, endTime)CalendarEvent設定活動開始與結束的日期和時間。
setTitle(title)CalendarEvent設定活動名稱。
setVisibility(visibility)CalendarEvent設定活動的顯示設定。

內容詳盡的說明文件

addEmailReminder(minutesBefore)

新增活動電子郵件提醒。提醒必須在活動開始前至少 5 分鐘,且時間不要超過 4 週 (40320 分鐘)。

// Gets an event by its ID. For an event series, use getEventSeriesById(iCalId) instead.
// TODO(developer): Replace the string with the event ID that you want to get.
const event = CalendarApp.getEventById('abc123456');

// Adds an email notification for 15 minutes before the event.
event.addEmailReminder(15);

參數

名稱類型說明
minutesBeforeInteger活動前的分鐘數

回攻員

CalendarEvent — 這個 CalendarEvent 用於鏈結

擲回

Error:如果活動有 5 則提醒,或是時間不在法律範圍內

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

addGuest(email)

將邀請對象加入活動。

// Example 1: Add a guest to one event
function addAttendeeToEvent() {
  // Replace the below values with your own
  let attendeeEmail = 'user@example.com'; // Email address of the person you need to add
  let calendarId = 'calendar_123@group.calendar.google.com'; // ID of calendar containing event
  let eventId = '123abc'; // ID of event instance

  let calendar = CalendarApp.getCalendarById(calendarId);
  if (calendar === null) {
    // Calendar not found
    console.log('Calendar not found', calendarId);
    return;
    }
  let event = calendar.getEventById(eventId);
  if (event === null) {
    // Event not found
    console.log('Event not found', eventId);
    return;
    }
  event.addGuest(attendeeEmail);
  }

// Example 2: Add a guest to all events on a calendar within a specified timeframe
function addAttendeeToAllEvents(){
// Replace the following values with your own
  let attendeeEmail = 'user@example.com'; // Email address of the person you need to add
  let calendarId = 'calendar_123@group.calendar.google.com'; // ID of calendar with the events
  let startDate = new Date("YYYY-MM-DD"); // The first date to add the guest to the events
  let endDate = new Date("YYYY-MM-DD"); // The last date to add the guest to the events

  let calendar = CalendarApp.getCalendarById(calendarId);
    if (calendar === null) {
    // Calendar not found
    console.log('Calendar not found', calendarId);
    return;
  }
  // Get the events within the specified timeframe
  let calEvents = calendar.getEvents(startDate,endDate);
  console.log(calEvents.length); // Checks how many events are found
  // Loop through all events and add the attendee to each of them
  for (var i = 0; i < calEvents.length; i++) {
  let event = calEvents[i];
  event.addGuest(attendeeEmail);
  }
}

參數

名稱類型說明
emailString邀請對象的電子郵件地址。

回攻員

CalendarEvent — 此 CalendarEvent 用於鏈結。

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

addPopupReminder(minutesBefore)

將新的彈出式通知新增至事件。通知時間至少須為 5 分鐘,且在事件發生前至少 4 週 (40320 分鐘)。

// Gets an event by its ID. For an event series, use getEventSeriesById(iCalId) instead.
// TODO(developer): Replace the string with the event ID that you want to get.
const event = CalendarApp.getEventById('abc123456');

// Adds a pop-up notification for 15 minutes before the event.
event.addPopupReminder(15);

參數

名稱類型說明
minutesBeforeInteger活動前的分鐘數

回攻員

CalendarEvent — 這個 CalendarEvent 用於鏈結

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

addSmsReminder(minutesBefore)

新增活動簡訊提醒。提醒必須在活動開始前至少 5 分鐘,且時間不要超過 4 週 (40320 分鐘)。

參數

名稱類型說明
minutesBeforeInteger活動前的分鐘數

回攻員

CalendarEvent — 這個 CalendarEvent 用於鏈結

擲回

Error:如果活動有 5 則提醒,或是時間不在法律範圍內

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

anyoneCanAddSelf()

決定使用者是否能將自己新增為日曆活動的邀請對象。

// Gets an event by its ID. For an event series, use getEventSeriesById(iCalId) instead.
// TODO(developer): Replace the string with the event ID that you want to get.
const event = CalendarApp.getEventById('abc123456');

// Determines whether people can add themselves as guests to the event and logs it.
console.log(event.anyoneCanAddSelf());

回攻員

Booleantrue如果非邀請對象可自行加入活動,請false進行此操作

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

deleteEvent()

刪除日曆活動。

// Gets an event by its ID.
// TODO(developer): Replace the string with the ID of the event that you want to delete.
const event = CalendarApp.getEventById('abc123456');

// Deletes the event.
event.deleteEvent();

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

deleteTag(key)

從事件中刪除鍵/值代碼。

參數

名稱類型說明
keyString標記鍵

回攻員

CalendarEvent — 這個 CalendarEvent 用於鏈結

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

getAllDayEndDate()

取得這項全天日曆活動的結束日期。(如果這不是全天事件,這個方法會擲回例外狀況)。傳回的 Date 代表在事件結束以指令碼的時區為準後一天的午夜。如要改用日曆的時區,請呼叫 getEndTime()

// Gets the user's default calendar. To get a different calendar, use getCalendarById()
// instead.
const calendar = CalendarApp.getDefaultCalendar();

// Creates an event named 'My all-day event' for May 16, 2023.
const event = calendar.createAllDayEvent('My all-day event', new Date('May 16, 2023'));

// Gets the event's end date and logs it.
const endDate = event.getAllDayEndDate();
console.log(endDate);

回攻員

Date:這項全天日曆活動的結束日期

擲回

Error — 如果這個活動並非全天活動

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

getAllDayStartDate()

取得這項全天日曆活動的開始日期。(如果這不是全天事件,此方法會擲回例外狀況)。傳回的 Date 代表活動開始的午夜 (以指令碼的時區為準)。如要改用日曆的時區,請呼叫 getStartTime()

// Gets the user's default calendar. To get a different calendar, use getCalendarById()
// instead.
const calendar = CalendarApp.getDefaultCalendar();

// Creates an event named 'My all-day event' for May 16, 2023.
const event = calendar.createAllDayEvent('My all-day event', new Date('May 16, 2023'));

// Gets the event's start date and logs it.
const startDate = event.getAllDayStartDate();
console.log(startDate);

回攻員

Date:這項全天日曆活動的開始日期

擲回

Error — 如果這個活動並非全天活動

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

getAllTagKeys()

取得已在事件上設定的所有代碼鍵。

回攻員

String[]:字串鍵陣列

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

getColor()

傳回日曆活動的顏色。

// Gets an event by its ID. For an event series, use getEventSeriesById(iCalId) instead.
// TODO(developer): Replace the string with the event ID that you want to get.
const event = CalendarApp.getEventById('abc123456');

// Gets the color of the calendar event and logs it.
const eventColor = event.getColor();
console.log(eventColor);

回攻員

String:以字串形式表示事件顏色,做為 CalendarApp.EventColor 值的索引 (1-11)。

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

getCreators()

取得活動建立者。

// Gets an event by its ID. For an event series, use getEventSeriesById(iCalId) instead.
// TODO(developer): Replace the string with the event ID that you want to get.
const event = CalendarApp.getEventById('abc123456');

// Gets a list of the creators of the event and logs it.
console.log(event.getCreators());

回攻員

String[]:活動建立者的電子郵件地址

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

getDateCreated()

取得事件的建立日期。您必須具備日曆的存取權。

// Opens the calendar by using its ID.
// To get the user's default calendar use CalendarApp.getDefault() instead.
// TODO(developer): Replace the calendar ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 1st, 2023 that takes place
// between 8:10 AM and 4:25 PM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Feb 01, 2023 08:10:00'), new Date('Feb 01, 2023 16:25:00'))[0];

if (event) {
 // If an event exists within the given time frame, gets the date that the event
 // was created and logs it.
 const eventCreated = event.getDateCreated();
 console.log(eventCreated);
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

回攻員

Date:建立日期

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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.
// To get the user's default calendar use CalendarApp.getDefault() instead.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 4th, 2023 that takes place
between 4:00 PM and 5:00 PM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Feb 04, 2023 16:00:00'), new Date('Feb 04, 2023 17:00:00'))[0];

if (event) {
 // If an event exists within the given time frame, sets the description of the event.
 event.setDescription('Important meeting');

 // Gets the description of the event and logs it.
 const description = event.getDescription();
 console.log(description);
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

回攻員

String:說明

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

getEmailReminders()

取得活動所有電子郵件提醒的分鐘數值。您必須具備 日曆的編輯權限。

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 4th, 2023 that takes place
between 5:00 PM and 6:00 PM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Feb 04, 2023 15:00:00'), new Date('Feb 04, 2023 18:00:00'))[0];

if (event) {
 // If an event exists within the given time frame, adds email reminders for the user to be
 // sent at 4 and 7 minutes before the event.
 event.addEmailReminder(4);
 event.addEmailReminder(7);

 // Gets the minute values for all email reminders that are set up for the user for this event
 // and logs it.
 const emailReminder = event.getEmailReminders();
 console.log(emailReminder);
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

回攻員

Integer[]:此陣列,每個值都對應至提醒觸發事件前的分鐘數

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

getEndTime()

取得這項日曆活動的結束日期和時間。您必須具備日曆的存取權。 針對非全天活動,這是定義事件結束時間的當下。對於只儲存結束日期 (而非日期和時間) 的全天活動,這會是活動結束自日曆時區當日開始的午夜。這樣就能比較所有類型活動的結束時間,但不一定會保留原始日期。

如果是全天事件,系統幾乎應一律呼叫 getAllDayEndDate(),以便優先使用這個方法。

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 1st, 2023 that takes place
// between 4:00 PM and 5:00 PM.
const event =
  calendar.getEvents(new Date('Feb 01, 2023 16:00:00'), new Date('Feb 01, 2023 17:00:00'))[0];

if (event) {
 // If an event exists within the given time frame, gets the date and time at which the
 // event ends and logs it.
 console.log(event.getEndTime());
} else {
 // If no event exists within the given time frame, logs that info to the console.
 console.log('No events exist for the specified range');
}

回攻員

Date:這項日曆活動的結束時間

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

getEventSeries()

取得此活動所屬的一系列週期性活動。您必須具備日曆的存取權。即使此事件不屬於任何系列,系統仍會傳回 CalendarEventSeries 物件,以便您新增週期設定。

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 18th, 2023 that takes place between
// 1:00 PM and 2:00 PM.
const event =
  calendar.getEvents(new Date('Feb 18, 2023 13:00:00'), new Date('Feb 18, 2023 14:00:00'))[0];

if (event) {
 // If an event exists within the given time frame, gets the event series for the event
 // and sets the color to pale green.
 event.getEventSeries().setColor(CalendarApp.EventColor.PALE_GREEN);
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

回攻員

CalendarEventSeries:此活動所屬的活動系列;如果尚未屬於特定係列活動,則請輸入新活動系列

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

getGuestByEmail(email)

取得邀請對象的電子郵件地址。

// Opens the calendar by its ID. You must have edit access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 25th, 2023 that takes place
// between 5:00 PM and 5:25 PM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Feb 25,2023 17:00:00'), new Date('Feb 25,2023 17:25:00'))[0];

// Gets a guest by email address.
const guestEmailId = event.getGuestByEmail('alex@example.com');

// If the email address corresponds to an event guest, logs the email address.
if (guestEmailId) {
  console.log(guestEmailId.getEmail());
}

參數

名稱類型說明
emailString房客的地址

回攻員

EventGuest:邀請對象,如果電子郵件地址未對應到邀請對象,則傳回空值

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

getGuestList()

取得活動邀請對象,包括活動擁有者。

// Opens the calendar by its ID. You must have edit access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 25th, 2023 that takes place
// between 5:00 PM and 5:25 PM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Feb 25,2023 17:00:00'), new Date('Feb 25,2023 17:25:00'))[0];

// Adds two guests to the event by using their email addresses.
event.addGuest('alex@example.com');
event.addGuest('cruz@example.com');

// Gets the guests list for the event.
const guestList = event.getGuestList();

// Loops through the list to get all the guests and logs their email addresses.
for (const guest of guestList){
  console.log(guest.getEmail());
}

回攻員

EventGuest[]:邀請對象的陣列

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

getGuestList(includeOwner)

取得活動邀請對象,包括活動擁有者。

// Opens the calendar by its ID. You must have edit access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 25th, 2023 that takes place
// between 5:00 PM and 5:25 PM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Feb 25,2023 17:00:00'), new Date('Feb 25,2023 17:25:00'))[0];

// Gets the guests list for the event, including the owner of the event.
const guestList = event.getGuestList(true);

// Loops through the list to get all the guests and logs it.
for (const guest of guestList) {
  console.log(guest.getEmail());
}

參數

名稱類型說明
includeOwnerBoolean是否要將擁有者納入訪客

回攻員

EventGuest[]:邀請對象的陣列

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

getId()

取得事件的專屬 iCalUID。請注意,calendar v3 API日曆進階服務所用的 iCalUID 和事件 id 並不相同,且無法交替使用。兩者的語意不同,就是在週期性事件中,每個事件發生時都有不同的 ids,而這些事件都共用相同的 iCalUID。

// Opens the calendar by its ID. You must have edit access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for January 5th, 2023 that takes place
// between 9:00 AM and 9:25 AM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Jan 05, 2023 09:00:00'), new Date('Jan 05, 2023 09:25:00'))[0];

// Gets the ID of the event and logs it.
console.log(event.getId());

回攻員

String:事件的 iCalUID

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

getLastUpdated()

取得活動上次更新日期。

// Opens the calendar by its ID. You must have view access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 1st, 2023 that takes place
between 4:00 PM and 5:00 PM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Feb 01, 2023 16:00:00'), new Date('Feb 01, 2023 17:00:00'))[0];

// Gets the date the event was last updated and logs it.
const eventUpdatedDate = event.getLastUpdated();
console.log(eventUpdatedDate);

回攻員

Date:上次更新日期

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

getLocation()

取得活動的位置。

// Opens the calendar by its ID. You must have edit access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 1st, 2023 that takes place
// between 4:10 PM and 4:25 PM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Feb 01, 2023 16:10:00'), new Date('Feb 01, 2023 16:25:00'))[0];

if (event) {
 // If an event exists within the given time frame, sets the location of the event to Mumbai.
 event.setLocation('Mumbai');

 // Gets the location of the event and logs it.
 const eventLocation = event.getLocation();
 console.log(eventLocation);
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

回攻員

String:活動地點

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

getMyStatus()

取得有效使用者的活動狀態 (例如參加或已邀請)。如果有效使用者是事件擁有者,一律會傳回 GuestStatus.OWNER

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.');

// Gets the first event from the calendar for February 1st, 2023 that takes place
// between 4:10 PM and 4:25 PM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Feb 01, 2023 16:10:00'), new Date('Feb 01, 2023 16:25:00'))[0];

if (event) {
 // If an event exists within the given time frame, gets the event status of
 // the effective user and logs it.
 const myStatus = event.getMyStatus();
 console.log(myStatus.toString());
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

回攻員

GuestStatus:狀態

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

getOriginalCalendarId()

取得建立這項活動的日曆 ID。

// Opens the calendar by its ID. You must have edit access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 25th, 2023 that takes place
// between 4:00 PM and 4:25 PM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Feb 25,2023 16:00:00'), new Date('Feb 25,2023 16:25:00'))[0];

if (event) {
 // If an event exists within the given time frame, gets the ID of the calendar where the
 // event was originally created and logs it.
 const calendarId = event.getOriginalCalendarId();
 console.log(calendarId);
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

回攻員

String:原始日曆的 ID

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

getPopupReminders()

取得活動的所有彈出式提醒的分鐘數值。

  // Opens the calendar by its ID. You must have edit access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 4th, 2023 that takes place
// between 5:05 PM and 5:35 PM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Feb 04, 2023 17:05:00'), new Date('Feb 04, 2023 17:35:00'))[0];

if (event) {
 // If an event exists within the given time frame, adds two pop-up reminders to the event.
 // The first reminder pops up 5 minutes before the event starts and the second reminder
 // pops up 3 minutes before the event starts.
 event.addPopupReminder(3);
 event.addPopupReminder(5);

 // Gets the minute values for all pop-up reminders for the event and logs it.
 const popUpReminder = event.getPopupReminders();
 console.log(popUpReminder);
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

回攻員

Integer[]:此陣列,每個值都對應至提醒觸發事件前的分鐘數

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

getSmsReminders()

取得活動所有簡訊提醒的分鐘數值。

回攻員

Integer[]:此陣列,每個值都對應至提醒觸發事件前的分鐘數

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

getStartTime()

取得這個日曆活動的開始日期和時間。如為非全天活動,這是定義事件開始當下的瞬時。對於只儲存開始日期 (而非日期和時間) 的全天活動,這會是活動開始以日曆所在時區開始的午夜。這樣就能比較所有類型事件的開始時間,但不一定會保留未經修改的原始年分。

對於全天事件,您通常應優先呼叫 getAllDayStartDate(),以便優先使用此方法。

// Opens the calendar by its ID. You must have edit access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 1st, 2023 that takes place
// between 4:10 PM and 4:25 PM.
const event =
  calendar.getEvents(new Date('Feb 01, 2023 16:10:00'), new Date('Feb 01, 2023 16:25:00'))[0];

// Gets the date and time at which this calendar event begins and logs it.
const startTime = event.getStartTime();
console.log(startTime);

回攻員

Date:這項日曆活動的開始時間

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

getTag(key)

取得事件的代碼值。

參數

名稱類型說明
keyString金鑰

回攻員

String:標記值

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

getTitle()

取得活動名稱。

// Opens the calendar by its ID. You must have edit access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for January 31st, 2023 that takes place
// between 9:05 AM and 9:15 AM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Jan 31, 2023 09:05:00'), new Date('Jan 31, 2023 09:15:00'))[0];

if (event) {
 // If an event exists within the given time frame, logs the title of the event.
 console.log(event.getTitle());
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

回攻員

String:標題

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

getVisibility()

取得活動的瀏覽權限。

// Opens the calendar by its ID. You must have edit access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 1st, 2023 that takes place
// between 4:10 PM and 4:25 PM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Feb 01, 2023 16:10:00'), new Date('Feb 01, 2023 16:25:00'))[0];

if (event) {
 // If an event exists within the given time frame, gets the visibility of the event
 // and logs it.
 const eventVisibility = event.getVisibility();
 console.log(eventVisibility.toString());
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

回攻員

Visibility:瀏覽權限值

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

guestsCanInviteOthers()

決定邀請對像是否能邀請其他邀請對象。

// Opens the calendar by its ID. You must have view access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 1st, 2023 that takes place
// between 9:35 AM and 9:40 AM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Feb 01, 2023 09:35:00'), new Date('Feb 01, 2023 09:40:00'))[0];

if (event) {
 // If an event exists within the given time frame, determines whether guests can invite
 // other guests and logs it.
 console.log(event.guestsCanInviteOthers());
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

回攻員

Boolean - 如果邀請對象可以邀請其他人,則為 true;如果邀請對象可以邀請,則為 false

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

guestsCanModify()

決定邀請對像是否能修改活動。

// Opens the calendar by its ID. You must have edit access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 1st, 2023 that takes place
// between 9:35 AM and 9:40 AM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Feb 01, 2023 09:35:00'), new Date('Feb 01, 2023 09:40:00'))[0];

if (event) {
 // If an event exists within the given time frame, sets the event so that guests can't
 // modify it.
 event.setGuestsCanModify(false);

 // Determines whether guests can modify the event and logs it.
 console.log(event.guestsCanModify());
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

回攻員

Boolean:如果邀請對象可以修改活動,則為 true;如果不是,則為 false

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

guestsCanSeeGuests()

決定邀請對像是否能看見其他邀請對象。

// Opens the calendar by its ID. You must have view access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 1st, 2023 that takes place
// between 9:35 AM and 9:40 AM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Feb 01, 2023 09:35:00'), new Date('Feb 01, 2023 09:40:00'))[0];

if (event) {
 // If an event exists within the given time frame, determines whether guests can see other
 // guests and logs it.
 console.log(event.guestsCanSeeGuests());
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

回攻員

Boolean:如果邀請對象可以看見其他邀請對象,則設為 true;如果不顯示其他邀請對象,則設為 false

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

isAllDayEvent()

指定這是否為全天活動。

// Opens the calendar by its ID. You must have view access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for January 31st, 2023 that takes place
// between 9:05 AM and 9:15 AM.
const event =
  calendar.getEvents(new Date('Jan 31, 2023 09:05:00'), new Date('Jan 31, 2023 09:15:00'))[0];

// Determines whether this event is an all-day event and logs it.
console.log(event.isAllDayEvent());

回攻員

如果活動是全天活動,則為 Boolean - true;如果不是全天活動,則為 false

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

isOwnedByMe()

判斷你是否為活動擁有者。

// Opens the calendar by its ID. You must have view access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for January 31st, 2023 that takes place
// between 9:05 AM and 9:15 AM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Jan 31, 2023 09:05:00'), new Date('Jan 31, 2023 09:15:00'))[0];

if (event) {
 // If an event exists within the given time frame, determines whether you're the owner
 // of the event and logs it.
 console.log(event.isOwnedByMe());
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

回攻員

Boolean - true 表示有效使用者擁有活動;如果不是有效使用者,則為 false

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

isRecurringEvent()

判斷該活動是否屬於活動系列。

// Opens the calendar by its ID. You must have view access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for Januart 31st, 2023 that takes place
// between 9:00 AM and 10:00 AM.
const event =
  calendar.getEvents(new Date('Jan 31, 2023 09:00:00'), new Date('Jan 31, 2023 10:00:00'))[0];

if (event) {
 // If an event exists within the given time frame, determines whether the event is part of an
 // event series and logs it.
 console.log(event.isRecurringEvent());
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

回攻員

Boolean:如果活動屬於活動系列,則為 true;如果不是,則為 false

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

removeAllReminders()

用於移除活動的所有提醒。

// Opens the calendar by its ID. You must have edit access to the calendar
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 1st, 2023 that takes place
// between 4:10 PM and 4:25 PM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Feb 1,2023 16:10:00'), new Date('Feb 1,2023 16:25:00'))[0];

if (event) {
 // If an event exists within the given time frame, removes all reminders from the event.
 event.removeAllReminders();
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

回攻員

CalendarEvent — 這個 CalendarEvent 用於鏈結

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

removeGuest(email)

將邀請對象從活動中移除。

// Example 1: Remove a guest from one event
function removeGuestFromEvent() {
  // Replace the below values with your own
  let attendeeEmail = 'user@example.com'; // Email address of the person you need to remove
  let calendarId = 'calendar_123@group.calendar.google.com'; // ID of calendar containing event
  let eventId = '123abc'; // ID of event instance

  let calendar = CalendarApp.getCalendarById(calendarId);
  if (calendar === null) {
    // Calendar not found
    console.log('Calendar not found', calendarId);
    return;
    }
  let event = calendar.getEventById(eventId);
  if (event === null) {
    // Event not found
    console.log('Event not found', eventId);
    return;
    }
  event.removeGuest(attendeeEmail);
  }

// Example 2: Remove a guest from all events on a calendar within a specified timeframe
function removeGuestFromAllEvents(){
// Replace the following values with your own
  let attendeeEmail = 'user@example.com'; // Email address of the person you need to remove
  let calendarId = 'calendar_123@group.calendar.google.com'; // ID of calendar with the events
  let startDate = new Date("YYYY-MM-DD"); // The first date to remove the guest from the events
  let endDate = new Date("YYYY-MM-DD"); // The last date to remove the attendee from the events

  let calendar = CalendarApp.getCalendarById(calendarId);
    if (calendar === null) {
    // Calendar not found
    console.log('Calendar not found', calendarId);
    return;
  }
  // Get the events within the specified timeframe
  let calEvents = calendar.getEvents(startDate,endDate);
  console.log(calEvents.length); // Checks how many events are found
  // Loop through all events and remove the attendee from each of them
  for (var i = 0; i < calEvents.length; i++) {
  let event = calEvents[i];
  event.removeGuest(attendeeEmail);
  }
}

參數

名稱類型說明
emailString邀請對象的電子郵件地址

回攻員

CalendarEvent — 這個 CalendarEvent 用於鏈結

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

resetRemindersToDefault()

使用日曆的預設設定重設提醒。

// Opens the calendar by its ID. You must have edit access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 1st, 2023 that takes place
// between 4:10 PM and 4:25 PM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Feb 1, 2023 16:10:00'), new Date('Feb 1, 2023 16:25:00'))[0];

if (event) {
 // If an event exists within the given time frame, resets the reminders using the calendar's
 // default settings.
 event.resetRemindersToDefault();
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

回攻員

CalendarEvent — 這個 CalendarEvent 用於鏈結

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

setAllDayDate(date)

設定活動日期。套用這個方法會將一般活動變更為全天活動。

// Opens the calendar by its ID. You must have edit access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 17th, 2023 that takes place
// between 4:00 PM and 5:00 PM.
const event =
  calendar.getEvents(new Date('Feb 17, 2023 16:00:00'), new Date('Feb 17, 2023 17:00:00'))[0];

if (event) {
 // If an event exists within the given time frame, sets the date of the event and updates
 // it to an all-day event.
 event.setAllDayDate(new Date('Feb 17, 2023'));
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

參數

名稱類型說明
dateDate事件的日期 (系統會忽略時間)

回攻員

CalendarEvent:這個用於鏈結的 CalendarEvent

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

setAllDayDates(startDate, endDate)

設定活動日期。套用這個方法會將一般事件變更為全天活動。

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 18th, 2023 that takes place
// between 4:00 PM and 5:00 PM.
const event =
  calendar.getEvents(new Date('Feb 18, 2023 16:00:00'), new Date('Feb 18, 2023 17:00:00'))[0];

if (event) {
 // If an event exists within the given time frame, sets the event to be an all-day event from
 // Feb 18th, 2023 until Feb 25th, 2023. Applying this method changes a regular event into an
 // all-day event.
 event.setAllDayDates(new Date('Feb 18, 2023'), new Date('Feb 25, 2023'));
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

參數

名稱類型說明
startDateDate事件開始的日期 (系統會忽略時間)
endDateDate事件結束的日期 (系統會忽略時間)

回攻員

CalendarEvent:這個用於鏈結的 CalendarEvent

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

setAnyoneCanAddSelf(anyoneCanAddSelf)

設定非邀請對像是否能將自己加入活動。

// Opens the calendar by its ID. You must have edit access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 15th, 2023 that takes place
// between 3:30 PM and 4:30 PM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Feb 15, 2023 15:30:00'), new Date('Feb 15, 2023 16:30:00'))[0];

if (event) {
 // If an event exists within the given time frame, sets the event so that non-guests
 // can't add themselves to the event.
 event.setAnyoneCanAddSelf(false);
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

參數

名稱類型說明
anyoneCanAddSelfBoolean是否有人可以邀請自己

回攻員

CalendarEvent — 這個 CalendarEvent 用於鏈結

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

setColor(color)

設定日曆活動的顏色。

// Opens the calendar by its ID. You must have edit access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 1st, 2023 that takes place
// between 4:10 PM and 4:25 PM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Feb 01, 2023 16:10:00'), new Date('Feb 01, 2023 16:25:00'))[0];

if (event) {
 // If an event exists within the given time frame, sets the color of the calendar event to
 // green.
 event.setColor(CalendarApp.EventColor.GREEN);
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

參數

名稱類型說明
colorString以字串表示的整數顏色索引,或是來自 CalendarApp.EventColor 的值。

回攻員

CalendarEvent - 此日曆活動:鏈結。

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

setDescription(description)

設定活動的說明。

// Opens the calendar by its ID. You must have edit access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 4th, 2023 that takes place
// between 5:05 PM and 5:35 PM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Feb 04, 2023 17:05:00'), new Date('Feb 04, 2023 17:35:00'))[0];

if (event) {
 // If an event exists within the given time frame, sets the description of the event to
 // 'Meeting.'
 event.setDescription('Meeting');
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

參數

名稱類型說明
descriptionString新說明

回攻員

CalendarEvent — 這個 CalendarEvent 用於鏈結

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

setGuestsCanInviteOthers(guestsCanInviteOthers)

設定邀請對像是否可以邀請其他邀請對象。

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own. You must have edit access to the calendar.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 1st, 2023 that takes place
// between 9:35 AM and 9:40 AM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Feb 01, 2023 09:35:00'), new Date('Feb 01, 2023 09:40:00'))[0];

if (event) {
 // If an event exists within the given time frame, sets the event so that guests can invite
 // other guests.
 event.setGuestsCanInviteOthers(true);
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

參數

名稱類型說明
guestsCanInviteOthersBoolean邀請對像是否可以邀請其他人

回攻員

CalendarEvent — 這個 CalendarEvent 用於鏈結

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

setGuestsCanModify(guestsCanModify)

設定邀請對像是否可以修改活動。

參數

名稱類型說明
guestsCanModifyBoolean邀請對像是否可以修改活動

回攻員

CalendarEvent — 這個 CalendarEvent 用於鏈結

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

setGuestsCanSeeGuests(guestsCanSeeGuests)

設定邀請對像是否能看到其他邀請對象。

參數

名稱類型說明
guestsCanSeeGuestsBoolean邀請對像是否可以看見其他人

回攻員

CalendarEvent — 這個 CalendarEvent 用於鏈結

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

setLocation(location)

設定事件的位置。

// Opens the calendar by its ID. You must have edit access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 1st, 2023 that takes place
// between 4:10 PM and 4:25 PM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Feb 01, 2023 16:10:00'), new Date('Feb 01, 2023 16:25:00'))[0];

if (event) {
 // If an event exists within the given time frame, sets the location of the event to Noida.
 event.setLocation('Noida');
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

參數

名稱類型說明
locationString新位置

回攻員

CalendarEvent — 這個 CalendarEvent 用於鏈結

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

setMyStatus(status)

設定有效使用者的活動狀態,例如參加或已邀請。

// Opens the calendar by its ID. You must have edit access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for February 1st, 2023 that takes place
// between 4:10 PM and 4:25 PM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Feb 01, 2023 16:10:00'), new Date('Feb 01, 2023 16:25:00'))[0];

if (event) {
 // If an event exists within the given time frame, sets the event status for the current user
 to maybe.
 event.setMyStatus(CalendarApp.GuestStatus.MAYBE);
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

參數

名稱類型說明
statusGuestStatus新的狀態

回攻員

CalendarEvent — 這個 CalendarEvent 用於鏈結

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

setTag(key, value)

設定事件的鍵/值標記來儲存自訂中繼資料。

參數

名稱類型說明
keyString標記鍵
valueString標記值

回攻員

CalendarEvent — 這個 CalendarEvent 用於鏈結

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

setTime(startTime, endTime)

設定活動開始與結束的日期和時間。套用這個方法會將全天活動變更為一般活動。

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Declares a start time of 11:00 AM on February 20th, 2023 and an end time of 12:00 PM on
// February 20th, 2023.
const startTime = new Date('Feb 20,2023 11:00:00');
const endTime = new Date('Feb 20, 2023  12:00:00');

// Creates an all-day event on February 20th, 2023.
const event = calendar.createAllDayEvent('Meeting', new Date('Feb 20,2023'));

// Updates the all-day event to a regular event by setting a start and end time for the event.
event.setTime(startTime, endTime);

參數

名稱類型說明
startTimeDate新的活動開始時間
endTimeDate新的活動結束

回攻員

CalendarEvent:這個用於鏈結的 CalendarEvent

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

setTitle(title)

設定活動名稱。

// Opens the calendar by its ID. You must have edit access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');

// Gets the first event from the calendar for January 31st, 2023 that takes place
// between 9:05 AM and 9:15 AM.
// For an event series, use calendar.getEventSeriesById('abc123456@google.com');
// and replace the series ID with your own.
const event =
  calendar.getEvents(new Date('Jan 31, 2023 09:05:00'), new Date('Jan 31, 2023 09:15:00'))[0];

if (event) {
 // If an event exists within the given time frame, changes its title to Event1.
 event.setTitle('Event1');
} else {
 // If no event exists within the given time frame, logs that information to the console.
 console.log('No events exist for the specified range');
}

參數

名稱類型說明
titleString新標題

回攻員

CalendarEvent — 這個 CalendarEvent 用於鏈結

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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

setVisibility(visibility)

設定活動的顯示設定。

參數

名稱類型說明
visibilityVisibility

回攻員

CalendarEvent — 這個 CalendarEvent 用於鏈結

授權

使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:

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