Microsoft Graph API Beta:订阅其他用户的事件通知

时间:2017-11-30 11:09:41

标签: microsoft-graph

我在https://apps.dev.microsoft.com

上创建了一个应用

使用以下应用程序权限:

Calendars.Read (Admin Only) Calendars.ReadWrite (Admin Only) User.Read.All (Admin Only)

管理员同意

然后通过此网址成功授予了管理员同意

https://login.microsoftonline.com/strixtechnology.onmicrosoft.com/adminconsent?client_id=bbb35336-faee-4c10-84b4-34136634db41&state=1234&redirect_uri=https%3A%2F%2Fdashmeetings.com%2Fmicrosoft%2Foauth

获取访问令牌

然后从

获取访问令牌
POST https://login.microsoftonline.com/common/oauth2/v2.0/token
带标题的

Content-Type=application/x-www-form-urlencoded

和具有键值对的正文

grant_type=client_credentials
client_id=bbb35336-faee-4c10-84b4-34136634db41
client_secret=xxx
scope=https://graph.microsoft.com/.default

这会返回一个访问令牌。

订阅通知

使用该访问令牌,我尝试订阅某个资源邮箱上的事件:

POST https://graph.microsoft.com/beta/subscriptions
带标题的

Content-Type=application/json
Authorization=Bearer <access_token_here>

和身体

{
   "changeType": "created,updated,deleted",
   "notificationUrl": "https://dashmeetings.com/microsoft/notify",
   "resource": "users/mahogany@strixtechnology.com/events",
   "expirationDateTime":"2017-12-01T11:00:00.0000000Z",
   "clientState":"1234"
}

这会返回401 Unauthorized

{
    "error": {
        "code": "ExtensionError",
        "message": "Operation: Create; Exception: [Status Code: Unauthorized; Reason: Unauthorized]",
        "innerError": {
            "request-id": "98ce5e5e-1ce4-4417-8c35-456a3cc0e696",
            "date": "2017-11-30T10:59:28"
        }
    }
}

这个问题与“Resource not found for the segment” using Graph subscription beta类似,但我没有任何运气也遵循相同的步骤

1 个答案:

答案 0 :(得分:0)

管理员同意网址必须

https://login.microsoftonline.com/common/adminconsent?client‌​_id=bbb35336-faee-4c‌​10-84b4-34136634db41‌​&state=1234&redirect‌​_uri=https%3A%2F%2Fd‌​ashmeetings.com%2Fmi‌​crosoft%2Foauth

和访问令牌地址:

https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/to‌​ken