使用 Office 365 REST 从共享日历中获取事件 API
Fetch events from shared calendar with Office 365 REST API
到目前为止,从用户加载共享日历是有效的。
但是,一旦您想加载事件,我们就会收到以下错误消息:
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"
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 以访问用户的日历。
到目前为止,从用户加载共享日历是有效的。 但是,一旦您想加载事件,我们就会收到以下错误消息:
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"
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 以访问用户的日历。