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

使用 Ruby 用戶端程式庫

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

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

試試看!

您可以使用下方的 APIs Explorer,針對即時資料呼叫這個方法,然後查看回應。