Microsoft Graph API:使用有效的企业 o365 帐户访问 SharePoint 网站时出现“租户没有 SPO 许可证”错误

问题描述 投票:0回答:1

我正在尝试通过 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 应用程序注册:

  • 创建应用程序注册并授予 Sites.ReadWrite.All 和 Files.ReadWrite.All 权限。
  • 这些权限已获得管理员同意。

SharePoint 权限:

  • 在 https://*.sharepoint.com/sites/Document_Repository/_layouts/15/appinv.aspx 中添加了具有以下权限请求 XML 的应用程序:
<AppPermissionRequests>
    <AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" />
</AppPermissionRequests>

许可证:

  • 已验证租户是否具有可用的 SharePoint Online 许可证。
  • 为用户分配 SharePoint Online 许可证。

Python 脚本:

sharepoint-online python-o365
1个回答
0
投票

首先,在开始编写任何代码之前,请使用 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,而不是它的名称/标题。

© www.soinside.com 2019 - 2024. All rights reserved.