【问题标题】:Fetch events from shared calendar with Office 365 REST API使用 Office 365 REST API 从共享日历中获取事件
【发布时间】:2018-08-10 09:57:28
【问题描述】:

到目前为止,从用户那里加载共享日历是可行的。 但是,一旦您要加载事件,我们就会收到以下错误消息:

ErrorAccessDenied
Access is denied. Check credentials and try again.

网址如下所示:

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"

【问题讨论】:

  • 您是否尝试为 calendarView 指定时间范围?
  • 是的,startDateTime 和 endDateTime 也设置了。注意:到目前为止 /me/ 工作正常,但 /users/{userId} 不行。我已经在问题中添加了查询。
  • 微软将不支持这种 Outlook REST 方式,现在应该使用 Graph API 来创建新的应用程序

标签: microsoft-graph-api office365api outlook-restapi


【解决方案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 来访问用户的日历。

【讨论】:

  • userPrincipalName / id 是什么意思?我可以从哪里得到它?可以分享一下样品吗?
  • @ngCoder userPrincipalName 是一个用户帐户名(也称为登录名)和一个电子邮件地址格式的域名,例如user@example.comuser@example.onmicrosoft.com。 “id”是 Azure AD 中用户的标识符 (GUID)。您可以调用/users 端点为所有用户获取这些值。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多