Calendars: update

更新日曆的中繼資料。立即試用查看範例

要求

HTTP 要求

PUT https://www.googleapis.com/calendar/v3/calendars/calendarId

參數

參數名稱 說明
路徑參數
calendarId string 日曆 ID。如要擷取日曆 ID,請呼叫 calendarList.list 方法。如果要存取目前登入使用者的主要日曆,請使用「primary」關鍵字。

授權

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

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

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

要求主體

在要求內文中,提供行事曆資源並附上下列屬性:

資源名稱 說明 附註
選用屬性
description string 日曆的說明。選用。 可寫入
location string 任意形式文字的日曆地理位置。選用。 可寫入
summary string 日曆的名稱。 可寫入
timeZone string 日曆的時區。(格式為 IANA 時區資料庫名稱,例如「Europe/Zurich」)。選用。 可寫入

回應

如果成功的話,這個方法會在回應主體中傳回行事曆資源

範例

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

Java

使用 Java 用戶端程式庫

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

// ...

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

// Retrieve a calendar
com.google.api.services.calendar.model.Calendar calendar =
    service.calendars().get('primary').execute();

// Make a change
calendar.setSummary("calendarSummary");

// Update the altered calendar
com.google.api.services.calendar.model.Calendar updatedCalendar =
    service.calendars().update(calendar.getId(), calendar).execute();

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

Python

使用 Python 用戶端程式庫

# First retrieve the calendar from the API.
calendar = service.calendars().get(calendarId='primary').execute()

calendar['summary'] = 'New Summary'

updated_calendar = service.calendars().update(calendarId=calendar['id'], body=calendar).execute()

print updated_calendar['etag']

PHP

使用 PHP 用戶端程式庫

// First retrieve the calendar from the API.
$calendar = $service->calendars->get('primary');

$calendar->setSummary('New Summary');

$updatedCalendar = $service->calendars->update('primary', $calendar);

echo $updatedCalendar->getEtag();

Ruby

使用 Ruby 用戶端程式庫

calendar = client.get_calendar('primary')
calendar.summary = "New Summary"
result = client.update_calendar(calendar.id, calendar)
print result.etag

試試看!

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