访问日历事件时使用Microsoft Graph API 401

时间:2019-04-14 18:20:39

标签: javascript microsoft-graph microsoft-graph-calendar

我目前正在尝试创建一个基本的网站,以便在树莓派上本地运行,从而向我显示当天的前景日历。但是,当我尝试访问https://graph.microsoft.com/v1.0/me/events端点时,出现401未经授权的错误。

这是用于简单的node.js表达服务器,用于与图形api进行交互的所有代码均来自Microsoft提供的javascript quickstart app。快速入门应用程序运行正常,我可以看到属于演示的https://graph.microsoft.com/v1.0/me端点的json响应,但是更改端点会导致401。

我已经确保在azure应用程序注册页面中启用了Calendar.read权限,并且在我的应用程序中已将calendar.read权限添加到了我的范围。登录时,登录弹出窗口会要求您阅读我的日历的权限,对我来说,该应用应有权访问我的日历。

我的应用程序配置(同样基于快速入门应用程序)如下所示:

const applicationConfig = {
    clientID: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
    authority: 'https://login.microsoftonline.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
    graphScopes: ['calendars.read', 'tasks.read'],
    graphEndpoint: 'https://graph.microsoft.com/v1.0/me/events',
};

除了这些更改之外,其余代码与示例代码相同。

1 个答案:

答案 0 :(得分:0)

您还应该在范围中包括User.Read。来自documentation on User.Read

  

允许用户登录该应用,并允许该应用读取已登录用户的个人资料。它还允许该应用读取已登录用户的基本公司信息。

const applicationConfig = {
    clientID: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
    authority: 'https://login.microsoftonline.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
    graphScopes: ['Users.Read', 'Calendars.Read', 'Tasks.Read'],
    graphEndpoint: 'https://graph.microsoft.com/v1.0/me/events',
};