获取日历

命名空间:microsoft.graph

重要

Microsoft Graph /beta 版本下的 API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。

获取 calendar 对象的属性和关系。 可以是用户的日历,也可以是 Microsoft 365 组的默认日历。

在下列两种情况下,应用可获取其他用户的日历:

  • 如果该应用具有应用程序权限,或者
  • 如果应用程序具有来自某个用户的相应委派权限,而另一个用户与该用户共享了日历,或者已为该用户授予委派的访问权限。 请参阅详细信息和示例。

此 API 可用于以下国家级云部署。

全局服务 美国政府 L4 美国政府 L5 (DOD) 由世纪互联运营的中国
✅ ✅ ✅ ✅

权限

根据事件所处日历类型和所请求的权限类型(委派型或应用程序),需要下列某一权限来调用此 API。 要了解详细信息(包括如何选择权限),请参阅权限。

日历 委派(工作或学校帐户) 委派(个人 Microsoft 帐户) 应用程序
用户日历 Calendars.ReadBasic、Calendars.Read、Calendars.ReadWrite Calendars.ReadBasic、Calendars.Read、Calendars.ReadWrite Calendars.ReadBasic、Calendars.Read、Calendars.ReadWrite
组日历 Group.Read.All、Group.ReadWrite.All 不支持。 不支持。

HTTP 请求

用户或组的默认 日历。

GET /me/calendar
GET /users/{id | userPrincipalName}/calendar
GET /groups/{id}/calendar

默认 calendarGroup 中用户的 日历。

GET /me/calendars/{id}
GET /users/{id | userPrincipalName}/calendars/{id}

指定 calendarGroup 中用户的 日历。

GET /me/calendarGroups/{id}/calendars/{id}
GET /users/{id | userPrincipalName}/calendarGroups/{id}/calendars/{id}

可选的查询参数

此方法支持 OData 查询参数 来帮助自定义响应。

请求标头

名称 类型 说明
Authorization string 持有者 {token}。 必填。 详细了解 身份验证和授权。

请求正文

请勿提供此方法的请求正文。

响应

如果成功,此方法在响应正文中返回 200 OK 响应代码和 calendar 对象。

示例

示例 1:获取默认日历

以下示例演示如何获取已登录用户的默认日历。

请求

以下示例显示了一个请求。

GET https://graph.microsoft.com/beta/me/calendar

响应

以下示例显示了相应的响应。

注意:为了提高可读性,可能缩短了此处显示的响应对象。

HTTP/1.1 200 OK
Content-type: application/json

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#me/calendars/$entity",
    "@odata.id": "https://graph.microsoft.com/beta/users('ddfcd489-628b-40d7-b48b-57002df800e5@1717622f-1d94-4d0c-9d74-709fad664b77')/calendars('AAMkAGI2TGuLAAA=')",
    "id": "AAMkAGI2TGuLAAA=",
    "name": "Calendar",
    "color": "auto",
    "isDefaultCalendar": false,
    "changeKey": "nfZyf7VcrEKLNoU37KWlkQAAA0x0+w==",
    "calendarGroupId":null,
    "canShare":true,
    "canViewPrivateItems":true,
    "hexColor": "",
    "isShared":false,
    "isSharedWithMe":false,
    "canEdit":true,
    "allowedOnlineMeetingProviders": [
                "teamsForBusiness"
            ],
    "defaultOnlineMeetingProvider": "teamsForBusiness",
    "isTallyingResponses": true,
    "isRemovable": false,
    "owner":{
        "name":"Samantha Booth",
        "address":"samanthab@contoso.com"
    }
}

示例 2:检索日历的共享级别

以下示例演示如何获取当前共享收件人的有效事件信息可见性。 sharingLevel 属性不表示编辑或委派权限。

请求

以下示例显示了一个请求。

GET https://graph.microsoft.com/beta/users/9f4d2a7b-8c31-4e56-a102-7b6c4d8e9f20/calendars/AAMkAGI2TGuLAAA=?%24select=id,name,sharingLevel

响应

以下示例显示了相应的响应。

HTTP/1.1 200 OK
Content-Type: application/json

{
  "@odata.context": "https://graph.microsoft.com/beta/$metadata#users('9f4d2a7b-8c31-4e56-a102-7b6c4d8e9f20')/calendars(id,name,sharingLevel)/$entity",
  "id": "AAMkAGI2TGuLAAA=",
  "name": "Calendar",
  "sharingLevel": "limited"
}