sharepoint - 在 SPfx 应用程序中获取用户事件的 Microsoft GraphAPI 403 错误
问题描述
我使用 Microsoft GraphAPI 编写了一个托管在 SharePoint Online 上的 SharePoint SPfx 应用程序,以获取用户配置文件信息和日历事件。根据微软文档,我在 package-solution.json 文件中声明了我的范围,并通过 SharePoint APi 管理页面批准了请求。我可以读取每个人的个人资料信息,但是,当我尝试访问日历事件但我自己的事件时,我收到错误 403。用户的日历不是私人的,它们对整个组织开放。
Package-solution.json 权限请求
"webApiPermissionRequests": [
{
"resource": "Microsoft Graph",
"scope": "User.Read"
},
{
"resource": "Microsoft Graph",
"scope": "User.ReadBasic.All"
},
{
"resource": "Microsoft Graph",
"scope": "People.Read"
},
{
"resource": "Microsoft Graph",
"scope": "Calendars.Read"
}
]
}
管理员批准的请求图片
请求代码:
private _searchUserCalendar(keyword: string): Promise<any[]> {
console.log("connection to GraphAPI event domain")
return new Promise<any[]>((resolve, reject) => {
this._context.msGraphClientFactory.getClient()
.then((client: MSGraphClient): void => {
client
.api(`/users/${keyword}/calendar/events`) // The api i.e> /me | /users
.version('v1.0')
.select("showAs,start,subject, end")
.top(5)
.get((error, response: any, rawResponse?: any) => {
if (error) {
console.log("ooops somethign went wrong get events",error);
reject(error);
}
var users:Array<any>=new Array<any>();
// Map the JSON response to the output array
if (response != null && response != undefined) {
console.log(response);
response.value.map((item: any) => {
console.log("found events for:", item)
}); // mapping over users
}
resolve(users);
});
});
});
}
错误响应
{error: {code: "ErrorAccessDenied", message: "Access is denied. Check credentials and try again.",…}}
error: {code: "ErrorAccessDenied", message: "Access is denied. Check credentials and try again.",…}
code: "ErrorAccessDenied"
message: "Access is denied. Check credentials and try again."
innerError: {request-id: "5dca3d4f-ab4c-4237-8ff4-78d8cacbd43b", date: "2020-01-16T19:05:26"}
request-id: "5dca3d4f-ab4c-4237-8ff4-78d8cacbd43b"
date: "2020-01-16T19:05:26"
我已经尝试了一切,任何帮助将不胜感激。
- 我在图形浏览器上测试了我的请求,效果很好
- 我卸载/重新安装了应用程序
- 我在 API 管理仪表板上拒绝并重新批准了权限请求
- 我将请求 URL 从使用用户 ID 更改为使用电子邮件(仅适用于我的个人资料,但仍不适用于其他任何人)
- 我让用户与我共享他们的日历并授予读/写权限,但仍然无法正常工作,因为该权限是特定于应用程序的,而不是用户委托的。
解决方案
User.Read
,并且User.ReadBasic.All
无权执行您正在尝试执行的操作。
此URL讨论日历阅读共享事件。
例如,Garth 与 John 共享了他的默认日历并授予 John 读取权限。如果 John 已登录您的应用并提供了委派权限(Calendars.Read.Shared 或 Calendars.ReadWrite.Shared),您的应用将能够访问 Garth 的默认日历和该日历中的事件,如下所述。
你可以尝试添加Calendar.Read.Shared
推荐阅读
- javascript - Vue.JS - 有没有办法通过方法触发我的工具提示组件
- angular - 如何在打字稿中获取用户本地时区?
- reactjs - 如何将 gltf 编码/压缩为 draco
- typescript - TypeScript:作为对象键的功能
- c# - 不匹配的编码将程序梯度生成从 C++ 移植到 C#
- python - 如何从python中的图像中去除白色模糊
- ssl - PWA 能否显示内容存储在另一台服务器上的 iframe(原始域的子域)
- android - DatePickerDialog 和 Theme.MaterialComponents
- javascript - 如何在不干扰滚动位置的情况下更新 html 表格?
- java - 如何在谷歌云 kubernates 中部署 docker 镜像