使用Office 365 REST API从共享日历中获取事件

问题描述 投票:3回答:1

从用户加载共享日历到目前为止工作。但是,只要您想加载事件,我们会收到以下错误消息:

ErrorAccessDenied
Access is denied. Check credentials and try again.

URL如下所示:

https://outlook.office.com/api/v2.0/users/{userName}/calendars/{sharedCalendarId}/calendarView

查询:

{
  "query": {
    "$select": "Subject,Location,Start,End,IsAllDay,BodyPreview,Extensions",
    "$expand": "Extensions($filter=Id eq \"Microsoft.OutlookServices.OpenTypeExtension.custom.string.here\")",
    "startDateTime": "2018-07-09T22:00:00.000Z",
    "endDateTime": "2018-11-09T23:00:00.000Z"
  },
  "headers": {
    "Prefer": [
      "odata.track-changes",
      "odata.maxpagesize=200"
    ]
  }
}

设置了以下范围:

"openid",
"profiles",
"offline_access", // for refresh token
"https://outlook.office.com/calendars.readwrite",
"https://outlook.office.com/calendars.read.shared",
"https://outlook.office.com/calendars.readwrite.shared"
microsoft-graph office365api outlook-restapi
1个回答
1
投票

始终代表当前用户(经过身份验证的用户)执行Outlook REST API请求。这就是为什么端点/me/calendars工作,但users/{userId}/calendars没有。您无法使用此API访问其他用户的日历。更多信息提供here

要访问其他用户的日历,您应该切换到Microsoft Graph API。然后您可以使用以下端点:

使用https://graph.microsoft.com/v1.0/

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

请记住指定permissions来访问用户的日历。

© www.soinside.com 2019 - 2024. All rights reserved.