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 日历的标识符。
可选属性
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();

// 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

试试看!

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