CalDAV API 開發人員指南's 指南
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
CalDAV 是 WebDAV 的擴充功能,可提供標準,讓用戶端存取遠端伺服器上的日曆資訊。
Google 提供 CalDAV 介面,您可以使用 CalDAV 通訊協定查看及管理日曆。
規格
Google 的 CalDAV 支援服務適用於下列相關規格:
我們尚未完整實作所有相關規格。不過,對於許多用戶端 (例如 Apple 的「日曆」應用程式),CalDAV 協定應可正確互通。
注意:為確保帳戶安全及防止濫用,Google 可能會在透過 CalDAV 存取資料的用戶端應用程式上設定 Cookie。
建立用戶端 ID
如要使用 CalDAV API,您必須擁有 Google 帳戶。如果已有帳戶,就可以開始使用了。
您必須先透過 Google API 控制台建立專案,向該控制台註冊用戶端,才能對 CalDAV API 發出要求。
前往 Google API 控制台。按一下「建立專案」,
輸入名稱,然後按一下「建立」。
接下來請啟用
CalDAV API。
如果想為專案啟用 API,請按照以下步驟操作:
- 在 Google API 控制台中開啟 API 程式庫。按照系統說明選取專案,或建立新專案。API 程式庫會列出所有可用的 API,並按照產品系列及熱門程度分組。
- 如果清單裡找不到您想啟用的 API,請使用搜尋功能。
- 選取要啟用的 API,然後按一下「Enable」按鈕。
- 如果系統顯示提示,請啟用帳單功能。
- 如果系統顯示提示,請接受 API 的服務條款。
如要執行
CalDAV API 要求,您需要
用戶端 ID 和
用戶端密鑰。
如要找出專案的用戶端 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. 的商標。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-29 (世界標準時間)。
[null,null,["上次更新時間: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"]]