SharePoint 使用 SharePoint Online REST API 获取所有站点和所有子站点

编程入门 行业动态 更新时间:2024-10-12 18:20:12
本文介绍了SharePoint 使用 SharePoint Online REST API 获取所有站点和所有子站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

对于 SharePoint Online 连接器,我们使用以下步骤获取所有网站:

For SharePoint Online connector We used following steps to fetch all sites:

第 1 步:使用以下权限 xml 在 SharePoint 实例上创建加载项

Step 1: Created Add-in on SharePoint instance with following permission xml

<AppPermissionRequests> <AppPermissionRequest Scope="sharepoint/content/tenant" Right="FullControl"/> <AppPermissionRequest Scope="sharepoint/content/sitecollection" Right="Read"/> </AppPermissionRequests>

第 2 步:使用下面的 API 获取所有站点和子站点

Step 2: Used below API to get all sites and subsites

<site_name>.sharepoint/_api/search/query?querytext='contentclass:STS_Site' &rowlimit=100

我们面临的问题 –

  • 上述端点返回所有 站点、子站点以及用户的个人站点(一个驱动器),而我们需要所有站点和子站点仅.
  • 请建议读取所有站点、所有子站点、所有文件夹和文件元数据所需的最低权限
  • Above endpoint is returning all sites, sub sites along with user’s personal site(One drive), while we need all sites and sub sites only.
  • Please suggest minimal required permission to read all site, all subsite, all folders and files metadata
  • 我们参考了以下链接:

    • www.ktskumar/2017/01/access-sharepoint-online-using-postman/
    • docs.microsoft/en-us/sharepoint/dev/sp-add-ins/add-in-permissions-in-sharepoint
    • docs.microsoft/en-us/sharepoint/dev/sp-add-ins/get-to-know-the-sharepoint-rest-service
    推荐答案

    您应该在端点中添加路径过滤器.

    You should add a path filter in the endpoint.

    普通网站集的路径类似于 tenant.sharepoint,而个人(One Drive)网站集的路径类似于 tenant-my.sharepoint/personal/*.

    Normal site collections have a path like tenant.sharepoint whereas personal (One Drive) site collections have path like tenant-my.sharepoint/personal/*.

    因此,修改您的端点如下:

    So, modify your endpoint as below:

    <site_name>.sharepoint/_api/search/query?querytext='contentclass:STS_Site Path:"<site_name>.sharepoint/*"'&rowlimit=500

    这只会返回以 <site_name>.sharepoint 路径开头的网站集,并将排除位于不同路径上的 One Drive 网站集.

    This will only return site collections starting with <site_name>.sharepoint path and will exclude the One Drive site collections which are on a different path.

    更多推荐

    SharePoint 使用 SharePoint Online REST API 获取所有站点和所有子站点

    本文发布于:2023-11-28 15:03:12,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1642893.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:站点   Online   SharePoint   API   REST

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!