如何使用office365-rest-python-api在sharepoint中添加文件夹

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

我已经在 sharepoint 中注册了一个具有网站读写访问权限的应用程序。 我想创建带有子文件夹的文件夹,我在官方文档中找到了解决方案:

def create_folder(dir_path):
    ctx = auth()
    target_folder_url = dir_path
    target_folder = ctx.web.ensure_folder_path(target_folder_url).execute_query()
    print(target_folder.serverRelativeUrl)

但通话后:

create_folder("/Shared Documents/Archive/2022/09/01")

我得到:

('-2147024891, System.UnauthorizedAccessException', 'Access denied.', "403 Client Error: Forbidden for url: https://<tenant>.sharepoint.com/sites/test_site/_api/Web/RootFolder/Folders/Add('Shared%20Documents'))

当我在浏览器中粘贴时:

https://<tenant>.sharepoint.com/sites/test_site/_api/Web/RootFolder/Folders/Add('Shared%20Documents')

我有这样的错误:

<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<m:code>-1, Microsoft.SharePoint.Client.ClientServiceException</m:code>
<m:message xml:lang="en-US">The HTTP method 'GET' cannot be used to access the resource 'Add'. The operation type of the resource is specified as 'Default'. Please use correct HTTP method to invoke the resource.</m:message>
</m:error>

有人能告诉我我做错了什么吗?

编辑:

我想通了。经许可:

<AppPermissionRequests AllowAppOnlyPolicy="true">
      <AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="Read"/>
      <AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="Write"/>
</AppPermissionRequests>

以这种方式创建文件夹是不够的。我必须更改为完全控制:

<AppPermissionRequests AllowAppOnlyPolicy="true">
          <AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl"/>
    </AppPermissionRequests>
python azure sharepoint office365api
© www.soinside.com 2019 - 2024. All rights reserved.