【发布时间】:2020-05-03 16:35:47
【问题描述】:
我使用 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"
}
]
}
管理员批准的请求图片
Screen of approved app permissions
请求代码:
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 更改为使用电子邮件(仅适用于我的个人资料,但仍不适用于其他任何人)
- 我让用户与我共享他们的日历并授予读/写权限,但仍然无法正常工作,因为该权限是特定于应用程序的,而不是用户委托的。
【问题讨论】:
-
你能添加对你做过的事情的描述吗?
-
@Fred 我用我尝试过的列表编辑了我的帖子,如果您需要任何其他说明,请告诉我
标签: sharepoint microsoft-graph-api spfx