CalDAV API 开发者指南
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
CalDAV 是 WebDAV 的扩展,为客户端访问远程服务器上的日历信息提供了标准。
Google 提供了一个 CalDAV 接口,您可以使用该接口通过 CalDAV 协议查看和管理日历。
规格
对于每项相关规范,Google 的 CalDAV 支持情况如下:
我们尚未完全实现所有相关规范。不过,对于许多客户端(例如 Apple 的“日历”应用),CalDAV 协议应该可以正常互操作。
注意:为了确保账号安全并防止滥用,Google 可能会在通过 CalDAV 访问数据的客户端应用中设置 Cookie。
创建客户端 ID
如需使用 CalDAV API,您需要拥有一个 Google 账号。如果您已有可用的账号,则无需进行任何操作。
在向 CalDAV API 发送请求之前,您必须通过创建项目在 Google API 控制台中注册您的客户端。
前往 Google API 控制台。点击创建项目,输入名称,然后点击创建。
下一步是激活
CalDAV API。
如需为您的项目启用 API,请执行以下操作:
- 在 Google API 控制台中打开 API 库。如果系统提示,请选择一个项目或创建一个新项目。API 库中列出了所有可用的 API(按产品系列和热门程度分组)。
- 如果列表中没有显示您要启用的 API,请使用搜索功能查找该 API。
- 选择您要启用的 API,然后点击启用按钮。
- 如果系统提示,请启用结算功能。
- 如果系统提示,请接受该 API 的服务条款。
如需执行
CalDAV API 请求,您需要
Client ID 和
Client Secret。
如需查找项目的客户端 ID 和客户端密钥,请执行以下操作:
- 选择现有的 OAuth 2.0 凭据或打开“凭据”页面。
- 如果您尚未创建项目的 OAuth 2.0 凭据,请点击创建凭据 > OAuth 客户端 ID,然后提供创建凭据所需的信息。
- 在 OAuth 2.0 客户端 ID 部分中查找客户端 ID。
如需了解详情,请点击相应客户 ID。
连接到 Google 的 CalDAV 服务器
如需使用 CalDAV 接口,客户端程序最初会通过以下两个起始点之一连接到日历服务器。无论采用哪种方式,连接都必须通过 HTTPS 进行,并且必须使用 OAuth 2.0 身份验证方案。除非请求通过 HTTPS 传送,并使用 Google 账号的 OAuth 2.0 身份验证,否则 CalDAV 服务器将拒绝验证请求。
尝试通过 HTTP 进行连接或使用基本身份验证会导致 HTTP 401 Unauthorized
状态代码。
如果客户端程序(例如 Apple 的日历应用)需要以主账号集合作为起点,则要连接到的 URI 为:
https://apidata.googleusercontent.com/caldav/v2/calid/user
其中,calid
应替换为要访问的日历的“日历 ID”。您可以通过 Google 日历网页界面找到此选项,具体操作如下:在日历名称旁边的下拉菜单中,选择日历设置。在随即显示的页面上,日历 ID 会显示在标记为日历地址的部分中。用户主日历的日历 ID 与该用户的电子邮件地址相同。
如果客户端程序(例如 Mozilla Sunbird)需要日历集合作为起点,则要连接到的 URI 为:
https://apidata.googleusercontent.com/caldav/v2/calid/events
旧端点 https://www.google.com/calendar/dav 已被弃用,不再受支持;使用该端点时,您需自行承担风险。
建议您改用上述新端点格式。
iCal® 是 Apple Inc. 的商标。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-29。
[null,null,["最后更新时间 (UTC):2025-08-29。"],[],[],null,["# CalDAV API Developer's Guide\n\nCalDAV is an extension of WebDAV that provides a standard for clients to access\ncalendar information on a remote server.\n\nGoogle provides a CalDAV interface that you can use to view and manage calendars\nusing the CalDAV protocol.\n\nSpecifications\n--------------\n\nFor each of the relevant specifications, Google's CalDAV support is as follows:\n\n- [rfc4918: HTTP Extensions for Web Distributed Authoring and Versioning\n (WebDAV)](http://tools.ietf.org/html/rfc4918)\n - Supports the HTTP methods `GET`, `PUT`, `HEAD`, `DELETE`, `POST`, `OPTIONS`, `PROPFIND` and `PROPPATCH`.\n - Does not support the HTTP methods `LOCK`, `UNLOCK`, `COPY`, `MOVE`, or `MKCOL`, or the `If*` header (except for `If-Match`).\n - Does not support arbitrary (user-defined) WebDAV properties.\n - Does not support WebDAV Access Control (rfc3744).\n- [rfc4791: Calendaring Extensions to WebDAV (CalDAV)](http://tools.ietf.org/html/rfc4791)\n - Supports the HTTP method `REPORT`. All reports except free-busy-query are implemented.\n - Does not support the HTTP method `MKCALENDAR`.\n - Does not support the `AUDIO` action.\n- [rfc5545: iCalendar](http://tools.ietf.org/html/rfc5545)\n - Data exposed in the CalDAV interface is formatted according to the iCalendar specification.\n - Does not currently support `VTODO` or `VJOURNAL` data.\n - Does not support the Apple iCal® extension to allow user-settable URL properties.\n- [rfc6578: Collection Synchronization for WebDAV](http://tools.ietf.org/html/rfc6578)\n - Client applications must switch to this mode of operation after the initial sync.\n- [rfc6638: Scheduling Extensions to CalDAV](http://tools.ietf.org/html/rfc6638)\n - Supports a trivial \"inbox,\" which is always empty.\n - Invitations you receive are automatically delivered into your \"events\" collection rather than being placed into your \"inbox.\"\n - Does not support free-busy lookup.\n- [caldav-ctag-02: Calendar Collection Entity Tag (CTag) in CalDAV](https://trac.calendarserver.org/browser/CalendarServer/trunk/doc/Extensions/caldav-ctag.txt)\n - The calendar `ctag` is like a resource `etag`; it changes when anything in the calendar has changed. This allows the client application to quickly determine that it does not need to synchronize any changed events.\n- [calendar-proxy: Calendar User Proxy Functionality in CalDAV](https://github.com/apple/ccs-calendarserver/blob/master/doc/Extensions/caldav-proxy.txt)\n - To improve the performance of calendar synching from iOS devices, which don't support delegation, using the `calendar-proxy-read-for` or `calendar-proxy-write-for` properties with an iOS UserAgent will fail.\n\nWe have not yet provided a full implementation of all of the relevant\nspecifications. However, for many clients such as Apple's Calendar app\nthe CalDAV protocol should interoperate correctly.\n\nNote: For account security and to prevent abuse, Google\nmight set cookies on client applications that access data via CalDAV.\n\nCreating your client ID\n-----------------------\n\nTo use the CalDAV API you need to have\na [Google Account](https://www.google.com/accounts/NewAccount).\nIf you already have an account you can use, then you're all set.\n\nBefore you can send requests to the CalDAV API, you must register\nyour client with the [Google API Console](https://console.cloud.google.com/) by creating a project.\n\n\nGo to the [Google API Console](https://console.cloud.google.com/project). Click **Create project** ,\nenter a name, and click **Create**.\nThe next step is to activate **CalDAV API** .\n\nTo enable an API for your project, do the following:\n\n1. [Open the API Library](https://console.cloud.google.com/apis/library) in the Google API Console. If prompted, select a project or create a new one. The API Library lists all available APIs, grouped by product family and popularity.\n2. If the API you want to enable isn't visible in the list, use search to find it.\n3. Select the API you want to enable, then click the **Enable** button.\n4. If prompted, enable billing.\n5. If prompted, accept the API's Terms of Service.\n\nTo perform **CalDAV API** requests you will need **Client ID** and **Client Secret** .\n\nTo find your project's client ID and client secret, do the following:\n\n1. Select an existing OAuth 2.0 credential or open the [Credentials page](https://console.cloud.google.com/apis/credentials).\n2. If you haven't done so already, create your project's OAuth 2.0 credentials by clicking **Create credentials \\\u003e OAuth client ID**, and providing the information needed to create the credentials.\n3. Look for the **Client ID** in the **OAuth 2.0 client IDs** section. For details, click the client ID.\n\n\u003cbr /\u003e\n\nConnecting to Google's CalDAV server\n------------------------------------\n\nTo use the CalDAV interface, a client program initially connects with the\ncalendar server at one of two starting points. In either case, the connection\nmust be made over HTTPS and must use the [OAuth 2.0](/workspace/calendar/auth)\nauthentication scheme. The CalDAV server will refuse to authenticate a request\nunless it arrives over HTTPS with OAuth 2.0 authentication of a Google account.\nAttempting to connect over HTTP or using Basic Authentication results in an HTTP\n`401 Unauthorized` status code.\n\nIf the client program (such as Apple's Calendar app) requires a\nprincipal collection as the starting point, the URI to connect to is: \n\n```\nhttps://apidata.googleusercontent.com/caldav/v2/calid/user\n```\n\nWhere \u003cvar class=\"apiparam\" translate=\"no\"\u003ecalid\u003c/var\u003e should be replaced by the\n\"calendar ID\" of the calendar to be accessed. This can be found through the\nGoogle Calendar web interface as follows: in the pull-down menu next to the\ncalendar name, select **Calendar Settings** . On the resulting page\nthe calendar ID is shown in a section labeled **Calendar\nAddress**. The calendar ID for a user's primary calendar is the same as\nthat user's email address.\n\nIf a client program (such as\n[Mozilla Sunbird](http://www.mozilla.org/projects/calendar/sunbird/)) requires a\ncalendar collection as the starting point, the URI to connect to is: \n\n```\nhttps://apidata.googleusercontent.com/caldav/v2/calid/events\n```\n\n\nThe old endpoint **https://www.google.com/calendar/dav** is\ndeprecated and no longer supported; use it at your own risk.\nWe recommend you transition to the new endpoint format described above.\n\n\niCal® is a trademark of Apple Inc.\n\n\u003cbr /\u003e"]]