问题描述
我正在尝试为特定用户订阅Microsoft Teams Presence API。
请求网址:
https://graph.microsoft.com/beta/subscriptions
请求正文
{
'changeType': 'created,updated','notificationUrl': 'https://<domain-name>/presence-notify/','resource': '/communications/presences/{id}','expirationDateTime': '2020-09-10T07:37:13Z','clientState': 'secretClientState'
}
响应
{
"error": {
"code": "ExtensionError","message": "Operation: Create; Exception: [Status Code: Forbidden; Reason: The request is not authorized for this user or application.]","innerError": {
"date": "2020-09-09T11:27:27","request-id": "c563f94d-3c10-4c09-be35-0d1993d9a112"
}
}
}
以下委托权限是由管理员请求并授予的:
-
Presence.Read
-
Presence.Read.All
客户证书图片
解决方法
您需要指定encryptionCertificate
。来自documentation:
,状态订阅需要encryption。如果未指定encryptionCertificate,则订阅创建将失败。
最后,我能够解决问题。如错误所述,The request is not authorized for this user or application
。因此,我认为访问令牌可能存在问题。实际上,我是代表App调用API,即token_type为client_credentials
的令牌。相反,我应该代表User调用API,即,Grant_type为password
的令牌,如documentation中明确提到的那样:
权限被委托。我没有使用任何encryptionCertificate
仍然可以成功订阅。