CalendarList: update

更新用户日历列表中的现有日历。立即试用查看示例

请求

HTTP 请求

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

参数

参数名称 说明
路径参数
calendarId string 日历标识符。要检索日历 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 日历内容是否显示在日历界面中。可选。默认值为 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

试试看!

请使用下面的 API Explorer 对实时数据调用此方法并查看响应。