代表使用者擁有或訂閱的日曆。
方法
內容詳盡的說明文件
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());
參數
名稱 | 類型 | 說明 |
---|---|---|
title | String | 活動的名稱。 |
date | Date | 事件的日期 (只會使用日期,系統會忽略時間)。 |
回攻員
CalendarEvent
:已建立的事件。
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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());
參數
名稱 | 類型 | 說明 |
---|---|---|
title | String | 活動的名稱。 |
startDate | Date | 事件開始的日期 (只會使用日期,系統會忽略時間)。 |
endDate | Date | 事件結束的日期 (只會使用日期,系統會忽略時間)。結束日期不含廣告活動。 |
回攻員
CalendarEvent
:已建立的事件。
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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());
參數
名稱 | 類型 | 說明 |
---|---|---|
title | String | 活動的名稱。 |
startDate | Date | 事件開始的日期 (只會使用日期,系統會忽略時間)。 |
endDate | Date | 事件結束的日期 (只會使用日期,系統會忽略時間)。結束日期不含廣告活動。 |
options | Object | 指定進階參數的 JavaScript 物件,如下所示。 |
進階參數
名稱 | 類型 | 說明 |
---|---|---|
description | String | 事件的說明。 |
location | String | 事件的位置。 |
guests | String | 要新增為邀請對象的電子郵件地址清單,以半形逗號分隔。 |
sendInvites | Boolean | 是否傳送邀請電子郵件 (預設值:false )。 |
回攻員
CalendarEvent
:已建立的事件。
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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());
參數
名稱 | 類型 | 說明 |
---|---|---|
title | String | 活動的名稱。 |
date | Date | 事件的日期 (只會使用日期,系統會忽略時間)。 |
options | Object | 指定進階參數的 JavaScript 物件,如下所示。 |
進階參數
名稱 | 類型 | 說明 |
---|---|---|
description | String | 事件的說明。 |
location | String | 事件的位置。 |
guests | String | 要新增為邀請對象的電子郵件地址清單,以半形逗號分隔。 |
sendInvites | Boolean | 是否傳送邀請電子郵件 (預設值:false )。 |
回攻員
CalendarEvent
:已建立的事件。
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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());
參數
名稱 | 類型 | 說明 |
---|---|---|
title | String | 系列活動的名稱 |
startDate | Date | 系列中第一個事件的日期 (只會使用日期,會略過時間) |
recurrence | EventRecurrence | 活動系列的週期設定 |
回攻員
CalendarEventSeries
:已建立的活動系列
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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());
參數
名稱 | 類型 | 說明 |
---|---|---|
title | String | 系列活動的名稱 |
startDate | Date | 系列中第一個事件的日期 (只會使用日期,會略過時間) |
recurrence | EventRecurrence | 活動系列的週期設定 |
options | Object | 指定進階參數的 JavaScript 物件,如下所示 |
進階參數
名稱 | 類型 | 說明 |
---|---|---|
description | String | 系列中活動的說明 |
location | String | 系列事件的位置 |
guests | String | 以半形逗號分隔的電子郵件地址清單,應新增為系列活動的邀請對象 |
sendInvites | Boolean | 是否要傳送邀請電子郵件 (預設值:false ) |
回攻員
CalendarEventSeries
:已建立的活動系列
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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());
參數
名稱 | 類型 | 說明 |
---|---|---|
title | String | 活動名稱 |
startTime | Date | 活動開始的日期和時間 |
endTime | Date | 活動結束的日期和時間 |
回攻員
CalendarEvent
:已建立的事件
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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());
參數
名稱 | 類型 | 說明 |
---|---|---|
title | String | 活動名稱 |
startTime | Date | 活動開始的日期和時間 |
endTime | Date | 活動結束的日期和時間 |
options | Object | 指定進階參數的 JavaScript 物件,如下所示 |
進階參數
名稱 | 類型 | 說明 |
---|---|---|
description | String | 活動的說明 |
location | String | 活動地點 |
guests | String | 以半形逗號分隔的電子郵件地址清單,以便將他們新增為邀請對象 |
sendInvites | Boolean | 是否要傳送邀請電子郵件 (預設值:false ) |
回攻員
CalendarEvent
:已建立的事件
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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());
參數
名稱 | 類型 | 說明 |
---|---|---|
description | String | 任意形式的活動說明 |
回攻員
CalendarEvent
:已建立的事件
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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());
參數
名稱 | 類型 | 說明 |
---|---|---|
title | String | 系列活動的名稱 |
startTime | Date | 系列中第一個活動開始的日期和時間 |
endTime | Date | 系列中第一個活動結束的日期和時間 |
recurrence | EventRecurrence | 活動系列的週期設定 |
回攻員
CalendarEventSeries
:已建立的活動系列
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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());
參數
名稱 | 類型 | 說明 |
---|---|---|
title | String | 系列活動的名稱 |
startTime | Date | 系列中第一個活動開始的日期和時間 |
endTime | Date | 系列中第一個活動結束的日期和時間 |
recurrence | EventRecurrence | 活動系列的週期設定 |
options | Object | 指定進階參數的 JavaScript 物件,如下所示 |
進階參數
名稱 | 類型 | 說明 |
---|---|---|
description | String | 系列中活動的說明 |
location | String | 系列事件的位置 |
guests | String | 以半形逗號分隔的電子郵件地址清單,應新增為系列活動的邀請對象 |
sendInvites | Boolean | 是否要傳送邀請電子郵件 (預設值:false ) |
回攻員
CalendarEventSeries
:已建立的活動系列
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:
-
https://www.googleapis.com/auth/calendar
-
https://www.google.com/calendar/feeds
deleteCalendar()
永久刪除日曆。使用者只能刪除自己擁有的日曆。
// Creates a calendar to delete. const calendar = CalendarApp.createCalendar('Test'); // Deletes the 'Test' calendar permanently. calendar.deleteCalendar();
擲回
Error
:如果是匯入的日曆。
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:
-
https://www.googleapis.com/auth/calendar
-
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
— 十六進位顏色字串 (「#rrggbb」)。
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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
:日曆的說明,
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:
-
https://www.googleapis.com/auth/calendar
-
https://www.googleapis.com/auth/calendar.readonly
-
https://www.google.com/calendar/feeds
getEventById(iCalId)
取得具有指定 ID 的事件。如果系列屬於預設日曆以外的日曆,則必須從該日曆呼叫此方法。呼叫 CalendarApp.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());
參數
名稱 | 類型 | 說明 |
---|---|---|
iCalId | String | 事件的 ID。 |
回攻員
CalendarEvent
:具有指定 ID 的事件;如果事件不存在或使用者無法存取,則為 null
。
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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
,則會傳回 CalendarEventSeries
,以及系列中的單一事件。請注意,如果活動系列屬於預設日曆以外的日曆,此方法必須從該 Calendar
呼叫;呼叫 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());
參數
名稱 | 類型 | 說明 |
---|---|---|
iCalId | String | 活動系列的 ID。 |
回攻員
CalendarEventSeries
:具有指定 ID 的系列叢書;如果系列叢書不存在或使用者無法存取系列叢書,則傳回 null
。
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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);
參數
名稱 | 類型 | 說明 |
---|---|---|
startTime | Date | 時間範圍的開始時間 |
endTime | Date | 時間範圍的結束,不含 |
回攻員
CalendarEvent[]
:在時間範圍內發生的事件
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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)
取得在指定時間範圍內發生的所有事件。
這個方法會傳回在指定時間範圍內開始、在時間範圍結束或涵蓋時間範圍的事件。如果沒有指定時區,系統將根據指令碼的時區解讀時間值 (可能會與日曆的時區不同)。
請注意,套用 start
和 max
後,系統會對 author
、search
或 statusFilters
進行篩選。這表示即使其他事件符合條件,傳回的事件數量可能少於 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);
參數
名稱 | 類型 | 說明 |
---|---|---|
startTime | Date | 時間範圍的開始時間 |
endTime | Date | 時間範圍的結束,不含 |
options | Object | 指定進階參數的 JavaScript 物件,如下所示 |
進階參數
名稱 | 類型 | 說明 |
---|---|---|
start | Integer | 所傳回第一個事件的索引 |
max | Integer | 要傳回的事件數量上限 |
author | String | 活動建立者用來篩選結果的電子郵件地址 |
search | String | 用於篩選搜尋結果的全文搜尋查詢 |
statusFilters[] | GuestStatus | 用於篩選結果的狀態陣列 |
回攻員
CalendarEvent[]
:在時間範圍內發生的事件,且符合條件
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:
-
https://www.googleapis.com/auth/calendar
-
https://www.googleapis.com/auth/calendar.readonly
-
https://www.google.com/calendar/feeds
getEventsForDay(date)
取得在特定日期發生的所有事件。
這個方法會傳回在特定日期開始、當天結束或涵蓋當天的事件。
請注意,系統只會使用 Date 物件的日期部分,並忽略時間部分。 系統會將日期視為日曆時區的隔天午夜至隔天午夜。
// Determines how many events are happening today. var today = new Date(); var events = CalendarApp.getDefaultCalendar().getEventsForDay(today); Logger.log('Number of events: ' + events.length);
參數
名稱 | 類型 | 說明 |
---|---|---|
date | Date | 擷取事件的日期 (只限使用日期;系統會忽略時間) |
回攻員
CalendarEvent[]
:在指定日期發生的事件
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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 物件的日期部分,並忽略時間部分。 系統會將日期視為日曆時區的隔天午夜至隔天午夜。
請注意,套用 start
和 max
後,系統會對 author
、search
或 statusFilters
進行篩選。這表示即使其他事件符合條件,傳回的事件數量可能少於 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);
參數
名稱 | 類型 | 說明 |
---|---|---|
date | Date | 擷取事件的日期 (只限使用日期;系統會忽略時間) |
options | Object | 進階篩選選項 |
進階參數
名稱 | 類型 | 說明 |
---|---|---|
start | Integer | 所傳回第一個事件的索引 |
max | Integer | 要傳回的事件數量上限 |
author | String | 活動建立者用來篩選結果的電子郵件地址 |
search | String | 用於篩選搜尋結果的全文搜尋查詢 |
statusFilters[] | GuestStatus | 用於篩選結果的狀態陣列 |
回攻員
CalendarEvent[]
:在指定日期發生的事件符合條件
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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。
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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
:這個日曆的名稱。
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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」)。
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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
。
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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
。
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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
表示不是您擁有的日曆)。
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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
表示不顯示
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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);
參數
名稱 | 類型 | 說明 |
---|---|---|
color | String | CalendarApp.Color 或十六進位顏色字串 (「#rrggbb」)。 |
回攻員
Calendar
- 這個用於鏈結的日曆。
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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.')
參數
名稱 | 類型 | 說明 |
---|---|---|
description | String | 這個日曆的說明 |
回攻員
Calendar
:這個用於鏈結的日曆
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:
-
https://www.googleapis.com/auth/calendar
-
https://www.google.com/calendar/feeds
setHidden(hidden)
設定是否在使用者介面中顯示日曆。
參數
名稱 | 類型 | 說明 |
---|---|---|
hidden | Boolean | true 可隱藏使用者介面中的日曆,false 則顯示該日曆 |
回攻員
Calendar
:這個用於鏈結的日曆
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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');
參數
名稱 | 類型 | 說明 |
---|---|---|
name | String | 新的名稱 |
回攻員
Calendar
:這個用於鏈結的日曆
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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);
參數
名稱 | 類型 | 說明 |
---|---|---|
selected | Boolean | true 可在使用者介面顯示日曆的活動,false 可隱藏這些活動 |
回攻員
Calendar
:這個用於鏈結的日曆
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 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');
參數
名稱 | 類型 | 說明 |
---|---|---|
timeZone | String | 以「long」格式指定的時區 (例如 Joda.org 列出的「America/New_York」)。 |
回攻員
Calendar
- 這個用於鏈結的日曆。
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:
-
https://www.googleapis.com/auth/calendar
-
https://www.google.com/calendar/feeds
unsubscribeFromCalendar()
取消訂閱使用者的日曆。使用者無法取消訂閱「我的日曆」清單中列出的日曆。他們可以取消訂閱「其他日曆」中列出的日曆。
// Gets the calendar by its ID. // TODO(developer): Replace the calendar ID with the calendar ID that you want to get. const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com'); // Unsubscribes the user from the calendar. const result = calendar.unsubscribeFromCalendar();
擲回
Error
— 如果這是自己擁有的日曆
授權
使用這個方法的指令碼必須取得下列一或多個範圍 (或相關的 REST API) 的適當範圍授權:
-
https://www.googleapis.com/auth/calendar
-
https://www.google.com/calendar/feeds