CalendarList: update

更新使用者日曆清單上的現有日曆。 立即試用查看範例

要求

HTTP 要求

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

參數

參數名稱 說明
路徑參數
calendarId string 日曆 ID。如要擷取日曆 ID,請呼叫 calendarList.list 方法。如果要存取目前登入使用者的主要日曆,請使用「primary」關鍵字。
自選查詢參數
colorRgbFormat boolean 是否使用 foregroundColorbackgroundColor 欄位寫入日曆顏色 (RGB)。如果使用這項功能,系統會將以索引為基礎的 colorId 欄位自動設為最符合的選項。選用設定。預設值為「False」。

授權

此要求需要取得下列範圍的授權:

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

詳情請參閱驗證和授權頁面。

要求主體

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

資源名稱 說明 附註
選用屬性
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();

// Retrieve the calendar list entry
CalendarListEntry calendarListEntry = service.calendarList().get("calendarId").execute();

// Make a change
calendarListEntry.setColorId("newColorId");

// Update the altered entry
CalendarListEntry updatedCalendarListEntry =
    service.calendarList().update(calendarListEntry.getId(), calendarListEntry).execute();

System.out.println(updatedCalendarListEntry.getEtag());

Python

使用 Python 用戶端程式庫

# First retrieve the calendarListEntry from the API.
calendar_list_entry = service.calendarList().get(calendarId='calendarId').execute()
calendar_list_entry['colorId'] = 'newColorId'

updated_calendar_list_entry = service.calendarList().update(
    calendarId=calendar_list_entry['id'], body=calendar_list_entry).execute()

print created_calendar_list_entry['etag']

PHP

使用 PHP 用戶端程式庫

// First retrieve the calendarListEntry from the API.
$calendarListEntry = $service->calendarList->get('calendarId');
$calendarListEntry->setColorId('newColorId');

$updatedCalendarListEntry = service->calendarList->update($calendarListEntry->getId(), $calendarListEntry);

echo $updatedCalendarListEntry->getEtag();

Ruby

使用 Ruby 用戶端程式庫

calendar_list_entry = client.get_calendar_list('calendarId')
calendar_list_entry.colorId = 'newColorId'
result = client.update_calendar_list(calendar_list_entry.id, calendar_list_entry)
print result.etag

試試看!

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