CalendarList: insert

將現有日曆插入使用者的日曆清單。 立即試用查看範例

要求

HTTP 要求

POST https://www.googleapis.com/calendar/v3/users/me/calendarList

參數

參數名稱 說明
選用的查詢參數
colorRgbFormat boolean 是否使用 foregroundColorbackgroundColor 欄位寫入日曆顏色 (RGB)。如果使用此功能,系統會自動將以索引為基礎的 colorId 欄位設為最符合的比對選項。選用設定。預設值為 False。

授權

此要求需要具有下列範圍的授權:

範圍
https://www.googleapis.com/auth/calendar

詳情請參閱「驗證與授權」網頁。

要求主體

在要求主體中,提供具有以下屬性的 calendarList 資源

屬性名稱 說明 附註
必要屬性
id string 日曆的 ID。
選用屬性
backgroundColor string 日曆的主要顏色,以十六進制格式「#0088aa」表示。這個屬性會取代以索引為基礎的 colorId 屬性。如要設定或變更這個屬性,您必須在 insertupdatepatch 方法的參數中指定 colorRgbFormat=true。選填。 可寫入
colorId string 日曆的顏色。此 ID 參照了顏色定義 calendar 區段中的項目 (請參閱顏色端點)。這個屬性已由 backgroundColorforegroundColor 屬性取代,且使用這些屬性時可以忽略。選填。 可寫入
defaultReminders[] list 已驗證使用者對這個日曆設定的預設提醒。 可寫入
defaultReminders[].method string 這項提醒使用的方法。可能的值包括:
  • email」- 系統會透過電子郵件傳送提醒。
  • popup」- 系統會透過使用者介面彈出式視窗傳送提醒。

新增提醒時為必填。

可寫入
defaultReminders[].minutes integer 活動開始時間前的分鐘數,以顯示提醒。有效值介於 0 到 40320 之間 (4 週以分鐘為單位)。

新增提醒時為必填。

可寫入
foregroundColor string 日曆的前景顏色,以十六進位格式「#ffffff」表示。這個屬性會取代以索引為基礎的 colorId 屬性。如要設定或變更這個屬性,您必須在 insertupdatepatch 方法的參數中指定 colorRgbFormat=true。選填。 可寫入
hidden boolean 是否要在清單中隱藏該日曆。選用設定。只有在日曆隱藏時,才會傳回這項屬性,在這種情況下,值為 true 可寫入
notificationSettings object 已驗證使用者收到的這個日曆的通知。 可寫入
notificationSettings.notifications[].method string 用於傳送通知的方法。可能的值為:
  • email」- 系統會透過電子郵件傳送通知。

新增通知時為必填。

可寫入
notificationSettings.notifications[].type string 通知類型,可能的值包括:
  • eventCreation」- 日曆出現新活動時傳送的通知。
  • eventChange」- 在活動變更時傳送通知。
  • eventCancellation」- 活動取消時所傳送的通知。
  • eventResponse」- 參與者回覆活動邀請後傳送的通知。
  • agenda」- 當天活動的議程 (在上午)。

新增通知時為必填。

可寫入
selected boolean 日曆內容是否顯示在日曆 UI 中。選用設定。預設值為 False。 可寫入
summaryOverride string 已驗證使用者為此日曆設定的摘要。選填。 可寫入

回應

如果成功,這個方法會在回應內文中傳回 calendarList 資源

範例

注意:這個方法適用的程式語言眾多,我們只在此提供部分程式碼範例,完整的支援語言清單請參閱用戶端程式庫頁面

Java

使用 Java 用戶端程式庫

import com.google.api.services.calendar.Calendar;
import com.google.api.services.calendar.model.CalendarListEntry;

// ...

// Initialize Calendar service with valid OAuth credentials
Calendar service = new Calendar.Builder(httpTransport, jsonFactory, credentials)
    .setApplicationName("applicationName").build();

// Create a new calendar list entry
CalendarListEntry calendarListEntry = new CalendarListEntry();
calendarListEntry.setId("calendarId");

// Insert the new calendar list entry
CalendarListEntry createdCalendarListEntry = service.calendarList().insert(calendarListEntry).execute();

System.out.println(createdCalendarListEntry.getSummary());

Python

使用 Python 用戶端程式庫

calendar_list_entry = {
    'id': 'calendarId'
}

created_calendar_list_entry = service.calendarList().insert(body=calendar_list_entry).execute()

print created_calendar_list_entry['summary']

PHP

使用 PHP 用戶端程式庫

$calendarListEntry = new Google_Service_Calendar_CalendarListEntry();
$calendarListEntry->setId("calendarId");

$createdCalendarListEntry = $service->calendarList->insert($calendarListEntry);

echo $createdCalendarListEntry->getSummary();

小茹

使用 Ruby 用戶端程式庫

entry = Google::Apis::CalendarV3::CalendarListEntry.new(
 id: 'calendarId'
)

result = client.insert_calendar_list(entry)
print result.summary

試試看!

使用下方的 APIs Explorer,針對即時資料呼叫這個方法,看看會有什麼結果。