获取共享或委托的 Outlook 日历及其事件Get shared or delegated Outlook calendar and its events

在 Outlook 中,日历所有者可与其他用户共享日历,并让他们查看或修改该日历中的事件;共享日历可以是所有者的主日历或由所有者创建的自定义日历。In Outlook, a calendar owner can share a calendar with other users and let them view or modify events in that calendar; the shared calendar can be the owner's primary calendar or a custom calendar created by the owner. 所有者还可以向其主日历授权代理人以代表其执行操作,接收或答复会议请求,或在主日历中创建或更改项目。The owner can also grant a delegate to their primary calendar and act on their behalf, to receive or respond to meeting requests, or create or change items in the primary calendar.

Microsoft Graph 支持以编程方式读取和写入其他用户已共享的日历中的事件、读取共享日历以及更新共享者的日历名称。Programmatically, Microsoft Graph supports reading and writing events in calendars that have been shared by other users, as well as reading the shared calendars, and updating the calendar name for sharees. 此支持还适用于已委托的日历。The support also applies to calendars that have been delegated. 本文的其余部分介绍如何在共享或委托的日历中读取事件。The rest of this article describes reading events in a shared or delegated calendar. 有关创建事件的信息,请参阅在共享日历或委托的日历中创建 Outlook 事件For creating events, refer to Create Outlook events in a shared or delegated calendar.

共享者:直接从日历所有者的邮箱获取共享日历或其事件Sharee: Get a shared calendar or its events directly from calendar owner's mailbox

以下三个示例假设这样的情景:在 Outlook 中,Alex 向 Megan 共享了他的主日历,并给予 Megan 读取权限。The three examples below use this scenario: in Outlook, Alex has shared his primary calendar with Megan and given Megan read permissions. 如果 Megan 登录你的应用,并提供_委托权限_ (Calendars.Read.Shared or Calendars.ReadWrite.Shared),代表 Megan,你的应用可以直接从 Alex 的邮箱中访问 Alex 的主日历及其事件。If Megan signs into your app and provides delegated permissions (Calendars.Read.Shared or Calendars.ReadWrite.Shared), on behalf of Megan, your app can access Alex' primary calendar and its events directly from Alex' mailbox.

三个示例指定了所有者的标识(Alex 的用户 ID 或用户主体名称)和 calendar 快捷方式。The three examples specify the owner's identity (Alex' user ID or user principal name) and the calendar shortcut. 这些示例仅访问与所有者的邮箱对应的日历和事件 ID。They access calendar and event IDs that correspond to only the owner's mailbox. 在共享者的邮箱(Megan 的用户 ID 或用户主体名称)中指定这些日历和事件 ID 将返回错误。Specifying these calendar and event IDs in the sharee's mailbox (Megan's user ID or user principal name) would return an error. 若要使用与共享者的邮箱对应的日历和事件 ID,请参阅共享者:从共享者的邮箱获取共享的自定义日历或其事件To use calendar and event IDs that correspond to the sharee's mailbox, see Sharee: Get shared, custom calendar or its events from sharee's mailbox.

注意:通过共享权限(Calendars.Read.Shared 或 Calendars.ReadWrite.Shared),你可以在共享或委托的日历中读取或写入事件。Note: The sharing permissions (Calendars.Read.Shared or Calendars.ReadWrite.Shared) allow you to read or write events in a shared or delegated calendar. 它们不支持订阅此类文件夹中的项的更改通知They do not support subscribing to change notifications on items in such folders. 若要对租户中共享、委托或任何其他用户或资源日历中的事件设置更改通知订阅,请使用应用程序权限 Calendars.Read。To set up change notification subscriptions on events in a shared, delegated, or any other user or resource calendar in the tenant, use the application permission, Calendars.Read.

Megan:直接从 Alex 的邮箱获取共享的主日历Megan: Get the shared, primary calendar directly from Alex' mailbox

以 Megan 的身份登录,直接从 Alex 的邮箱获取 Alex 向 Megan 共享的主日历:Signed in as Megan, get the primary calendar that Alex has shared with Megan, directly from Alex' mailbox:

GET https://graph.microsoft.com/v1.0/users/{Alex-userId | Alex-userPrincipalName}/calendar

成功完成后,你将收到 HTTP 200 OK 消息和一个日历实例,该实例表示 Alex 在Alex 的邮箱中共享的主日历。On successful completion, you'll get HTTP 200 OK and a calendar instance that represents Alex' shared, primary calendar, in Alex' mailbox.

Megan:直接从 Alex 的邮箱获取共享主日历中的事件Megan: Get an event in the shared, primary calendar directly from Alex' mailbox

以 Megan 的身份登录,你的应用可以直接从 Alex 的邮箱获取 Alex 向 Megan 共享的主日历中的特定事件:Signed in as Megan, your app can get a specific event in the primary calendar that Alex has shared with Megan, directly from Alex' mailbox:

GET https://graph.microsoft.com/v1.0/users/{Alex-userId | Alex-userPrincipalName}/calendar/events/{id}

成功完成后,你将收到 HTTP 200 OK 消息以及 Alex 的主日历中由 {id} 标识的事件实例(直接从 Alex 的邮箱获取)。On successful completion, you'll get HTTP 200 OK and the event instance identified by {id} in Alex' primary calendar, directly from Alex' mailbox.

Megan:从 Alex 的邮箱获取共享主日历中的所有事件Megan: Get all the events in the shared, primary calendar from Alex' mailbox

以 Megan 的身份登录,直接从 Alex 的邮箱获取 Alex 向 Megan 共享的主日历中的所有事件:Signed in as Megan, get all the events in the primary calendar that Alex has shared with Megan, directly from Alex' mailbox:

GET https://graph.microsoft.com/v1.0/users/{Alex-userId | Alex-userPrincipalName}/calendar/events

成功完成后,你将收到 HTTP 200 OK 消息以及 Alex 的主日历中的一组事件实例(直接从 Alex 的邮箱获取)。On successful completion, you'll get HTTP 200 OK and a collection of event instances in Alex' primary calendar, directly from Alex' mailbox.

如果 Alex 已委托 Megan 访问 Alex 的主日历,或者 Alex 向 Megan 委托了其整个邮箱,则将适用同样的 GET 功能。The same GET capabilities apply if Alex has delegated Megan access to Alex' primary calendar, or if Alex has delegated Megan his entire mailbox.

如果 Alex 尚未向 Megan 共享也未委托其主日历,则在前面的 GET 操作中指定 Alex 的用户 ID 或用户主体名称将返回错误。If Alex has not shared nor delegated his primary calendar with Megan, specifying Alex’s user ID or user principal name in the preceding GET operations will return an error.

共享者:从共享者的邮箱获取共享的自定义日历或其事件Sharee: Get shared, custom calendar or its events from sharee's mailbox

如果 Alex 向 Adele 共享了一个_自定义_日历(例如,名为“Kids parties”的日历),并且 Adele 提供了委托权限(Calendars.Read 或 Calendars.ReadWrite),则你的应用可以从 Adele 邮箱中的 Alex 日历本地副本获取事件或日历,如下所述。If Alex has shared a custom calendar (as an example, a calendar named "Kids parties") with Adele, and Adele has provided delegated permissions (Calendars.Read or Calendars.ReadWrite), your app can get the events or calendar from the local copy of Alex' calendar in Adele's mailbox, as described below.

  1. 以 Adele 的身份登录,使用以下任一请求获取 Adele 有权访问的所有日历,包括共享的自定义日历。Signed in as Adele, use either of the following requests to get all the calendars that Adele has access to, including the shared custom calendar.

    GET https://graph.microsoft.com/v1.0/me/calendars
    GET https://graph.microsoft.com/v1.0/users/{Adele-userId | Adele-userPrincipalName}/calendars
    

    成功后的响应包括响应代码 HTTP 200 以及 Adele 有权访问的一组日历,包括所有者名称为“Alex Wilber”的日历(“Kids parties”),作为响应中的第二个日历。A successful response includes the response code HTTP 200, and the collection of calendars that Adele has access to, including the calendar ("Kids parties") that has the owner name as "Alex Wilber" as the second calendar in the response. 对于共享者“Adele”,共享日历的 canShare 属性始终为 false。For a sharee, Adele, the canShare property of the shared calendar is always false.

    HTTP/1.1 200 OK
    Content-type: application/json
    
    {
        "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('d3b9214b-dd8b-441d-b7dc-c446c9fa0e69')/calendars",
        "value": [
            {
                "id": "AQMkADU5NAAAJMjAAAAA==",
                "name": "Calendar",
                "color": "auto",
                "changeKey": "NDznl+Uh50WkanaCOKHkaQAAAAACXQ==",
                "canShare": true,
                "canViewPrivateItems": true,
                "canEdit": true,
                "owner": {
                    "name": "Adele Vance",
                    "address": "AdeleV@contoso.OnMicrosoft.com"
                }
            },
            {
                "id": "AAMkADAABf0JlyAAA=",
                "name": "Kids parties",
                "color": "lightYellow",
                "changeKey": "NDznl+Uh50WkanaCOKHkaQAAYumJRQ==",
                "canShare": false,
                "canViewPrivateItems": false,
                "canEdit": false,
                "owner": {
                    "name": "Alex Wilber",
                    "address": "AlexW@contoso.OnMicrosoft.com"
                }
            }
        ]
    }
    
  2. 以 Adele 的身份登录,获取共享日历或获取共享日历中的一个或多个事件(使用步骤 1 的响应中的第二个日历 ID)。Signed in as Adele, get the shared calendar, or get one or more events in the shared calendar, using the second calendar ID in the response from step 1. 共享日历的 ID 及其事件对应于 Adele 邮箱中的 Alex 日历本地副本。The IDs of the shared calendar and its event correspond to the local copy of Alex' calendar in Adele's mailbox.

    GET https://graph.microsoft.com/v1.0/me/calendars/AAMkADAABf0JlyAAA=
    GET https://graph.microsoft.com/v1.0/users/{Adele-userId | Adele-userPrincipalName}/calendars/AAMkADAABf0JlyAAA=
    
    GET https://graph.microsoft.com/v1.0/me/calendars/AAMkADAABf0JlyAAA=/events/{id}
    GET https://graph.microsoft.com/v1.0/users/{Adele-userId | Adele-userPrincipalName}/calendars/AAMkADAABf0JlyAAA=/events/{id}
    
    GET https://graph.microsoft.com/v1.0/me/calendars/AAMkADAABf0JlyAAA=/events
    GET https://graph.microsoft.com/v1.0/users/{Adele-userId | Adele-userPrincipalName}/calendars/AAMkADAABf0JlyAAA=/events
    

成功完成后,你将收到 HTTP 200 OK 消息以及所请求的一个或多个事件或 Alex 向 Adele 共享的日历。On successful completion, you'll get HTTP 200 OK and the requested event, events, or calendar that Alex has shared with Adele.

后续步骤Next steps

详细了解以下信息:Find out more about: