为 OneDrive Business 创建订阅 returns 403 禁止

Create subscription for OneDrive Business returns 403 forbidden

我正在使用 Microsoft Graph API 构建 OneDrive 并与之集成。一切运行良好,我已经能够注册我的应用程序、获取令牌、导航 OneDrive 项目和下载文件。

我开始创建订阅以在用户执行某些操作时接收来自 OneDrive 的通知。当用户使用 "personal account" 登录时,这没有任何问题,但是当他们使用 "work or school" 帐户时,我收到以下错误消息:

{
  "error": {
    "code": "ExtensionError",
    "message": "Operation: Create; Exception: [Status Code: Forbidden; Reason: The caller does not have permission to perform the action.]",
    "innerError": {
      "request-id": "ffaf7fae-e0b0-4cd8-b911-bac4c2fb290a",
      "date": "2019-09-18T00:18:40"
    }
  }
}

这是我创建订阅的调用:

curl -X POST \
  https://graph.microsoft.com/v1.0/subscriptions \
  -H 'Authorization: Bearer [access_token]' \
  -H 'Content-Type: application/json' \
  -H 'Host: graph.microsoft.com' \
  -d '        {
            "resource": "me/drive/root",
            "changeType": "updated",
            "clientState": "[email_Address]",
            "notificationUrl": "https://webhook_url",
            "expirationDateTime": "2019-09-19T04:43:47.6099364+00:00"
        }'

用户有 Files.ReadWrite.All 权限,基于 documentation 应该足够了。

我遇到了同样的问题。唯一的区别是我试图在商业 OneDrive 路径 /users/<id>/drive/root 上设置 driveItem 订阅,但在响应中遇到与您相同的错误。

因此,使用相同的访问令牌,我执行了 GET /v1.0/users/<id>/drive/root 并从响应中获取了父项的 driveId。然后我尝试在 /drives/<driveId>/root 创建订阅并且成功了。所有请求都使用相同的访问令牌,而以前的方式曾经工作了几个月。

所以您可以尝试为您的 /me/drive/root 执行 GET,看看是否可以使用 driveId.

进行设置

作为奖励,订阅现在可以像我预期的那样发送网络挂钩。