无法使用应用程序守护程序令牌访问用户日历

问题描述

我一直在尝试使用MS graph API访问用户的数据。我一直在遵循官方文档,并且已经正确配置了应用程序和权限。

我也遵循此code_sample,并使用它来获取应用程序的守护程序令牌。

使用令牌,我可以针对以下端点成功获取数据:

https://graph.microsoft.com/v1.0/users/204e3e4f-xxxx-xxxx-xxxx-509934e1

数据如下:

{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users/$entity","businessPhones":[],"displayName":"developers@outlook.com Tiwari","givenName":"developers@outlook.com","jobTitle":null,"mail":null,"mobilePhone":null,"officeLocation":null,"preferredLanguage":null,"surname":"Tiwari","userPrincipalName":"developers_outlook.com#EXT#@webdevelopers.onmicrosoft.com","id":"204e3e4f-x-xxxxx-xxxxxxx-509934e14fa8"}

但是,我无法获取比这更多的数据。即使我已经检查了我应用程序的所有“应用程序”权限,所有其他端点也会引发“ 401未经授权”异常。

我正在尝试通过以下端点来获取上述用户的日历:

https://graph.microsoft.com/v1.0/users/204e3e4f-xxxx-xx-xxxxz-509934e14fa8/calendar
https://graph.microsoft.com/v1.0/users/204e3e4f-xxx-xxx-xxxxx-509934e14fa8/calendars

这两个都给出401。

有人可以建议我是否想念一些东西。我什至反编译了jwt令牌,它清楚地显示了添加的所有以下范围:

"roles": [
    "Schedule.ReadWrite.All","OnlineMeetings.Read.All","Mail.ReadWrite","OnlineMeetings.ReadWrite.All","User.ReadWrite.All","Calendars.Read","Mail.ReadBasic.All","Files.ReadWrite.All","User.Read.All","Schedule.Read.All","Files.Read.All","Organization.ReadWrite.All","Mail.Read","Calendars.ReadWrite","Mail.Send","Organization.Read.All","Mail.ReadBasic"
  ],

请帮助。

解决方法

要访问日历事件,应调用以下端点:

GET /users/{id | userPrincipalName}/events

日历文档在这里:https://docs.microsoft.com/en-us/graph/api/user-list-events

,

从您对Chris Johnson答案的评论来看,您使用的是个人帐户。仅应用令牌无法访问个人帐户,而且由于没有管理员的概念,因此您甚至无法使用个人帐户获得令牌。

仅应用程序需要管理员同意,当她同意时,她将授予对租户中所有资源的访问权限。个人帐户不在工作/学校租户中,因此不在范围之内。即使您已将该个人帐户添加为工作/学校租户中的客人,其日历仍托管在租户之外,并且不受限制。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...