[英]Microsoft Graph API 401 when accessing calendar events
I'm currently trying to create a basic website to run locally on a raspberry pi that shows me my outlook calendar for the day. 我目前正在尝试创建一个基本的网站,以便在树莓派上本地运行,从而向我显示当天的前景日历。 However, when I try and access the https://graph.microsoft.com/v1.0/me/events
endpoint, I get a 401 unauthorized error. 但是,当我尝试访问https://graph.microsoft.com/v1.0/me/events
端点时,出现401未经授权的错误。
This is for a simple node.js express server, with all of the code for interacting with the graph api coming from the javascript quickstart app provided by Microsoft. 这是用于简单的node.js Express服务器,用于与图形api交互的所有代码均来自Microsoft提供的javascript quickstart应用 。 The quickstart app works fine, and I'm able to see the json response for the https://graph.microsoft.com/v1.0/me
endpoint that is part of the demo, but changing the endpoint causes a 401. 快速入门应用程序运行正常,并且我能够看到作为演示一部分的https://graph.microsoft.com/v1.0/me
端点的json响应,但是更改该端点会导致401。
I've made sure in the azure app registration page that I've enabled the Calendar.read
permission, and in my app I've added the calendar.read
permission to my scope. 我已经确定在azure应用程序注册页面中已启用Calendar.read
权限,并且在我的应用程序中已将calendar.read
权限添加到了我的范围。 When I login, the login popup window asks for permission to read my calendar which to me says that the app should have access to my calendar. 登录时,登录弹出窗口会要求您阅读我的日历的权限,对我来说,该应用程序应该可以访问我的日历。
My application configuration (again based off of the quickstart app) looks like this: 我的应用程序配置(同样基于quickstart应用程序)如下所示:
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',
};
Other than these changes, the rest of the code is identical to the sample code. 除了这些更改之外,其余代码与示例代码相同。
You should also include User.Read
in your scopes. 您还应该在范围内包括User.Read
。 From the documentation on User.Read : 从User.Read的文档中 :
Allows users to sign-in to the app, and allows the app to read the profile of signed-in users. 允许用户登录到该应用,并允许该应用读取已登录用户的个人资料。 It also allows the app to read basic company information of signed-in users. 它还允许该应用读取已登录用户的基本公司信息。
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',
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.