我正在尝试通过 Python 脚本使用 Microsoft Graph API 访问 SharePoint 网站。尽管已在 Azure AD 中授予必要的权限并分配许可证,但我仍然遇到以下错误:
Failed to get site ID. Status code: 400
{
'error': {
'code': 'BadRequest',
'message': 'Tenant does not have a SPO license.',
'innerError': {
'date': '2024-05-22T12:52:33',
'request-id': 'cd207c1f-5bbc-435d-b6e3-94170d9e6aff',
'client-request-id': 'cd207c1f-5bbc-435d-b6e3-94170d9e6aff'
}
}
}
Azure AD 应用程序注册:
SharePoint 权限:
<AppPermissionRequests>
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" />
</AppPermissionRequests>
许可证:
Python 脚本:
首先,在开始编写任何代码之前,请使用 Microsoft Graph Explorer 尝试对 Microsoft Graph 的每次调用。
首先尝试调用根站点的API:
https://graph.microsoft.com/v1.0/sites/root
请注意,根站点的 ID 如下所示:
m365x214355.sharepoint.com,5a58bb09-1fba-41c1-8125-69da264370a0,9f2ec1da-0be4-4a74-9254-973f0add78fd
这是一个站点主机名和 2 个以逗号分隔的 ID。
对特定站点的任何调用都将采用这种格式,因此:
https://graph.microsoft.com/v1.0/sites/:siteId/drives
变成这样:
https://graph.microsoft.com/v1.0/sites/m365x214355.sharepoint.com,5a58bb09-1fba-41c1-8125-69da264370a0,9f2ec1da-0be4-4a74-9254-973f0add78fd/drives
这提供了站点的驱动器列表(包括文档存储库)。
从那里您可以进一步查询 Microsoft Graph。
此外,您需要“Document_Repository”的driveItem ID,而不是它的名称/标题。