SharePoint 使用 SharePoint Online REST API 获取所有站点和所有子站点 [英] SharePoint Get all sites and all sub sites using 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="http://sharepoint/content/tenant" Right="FullControl"/>
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="Read"/>
</AppPermissionRequests>
第 2 步:使用下面的 API 获取所有站点和子站点
Step 2: Used below API to get all sites and subsites
https://<site_name>.sharepoint.com/_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 allsites and sub sites
only. - Please suggest minimal required permission to read all site, all subsite, all folders and files metadata
我们参考了以下链接:
- http://www.ktskumar.com/2017/01/access-sharepoint-online-using-postman/
- https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/add-in-permissions-in-sharepoint
- https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/get-to-know-the-sharepoint-rest-service
推荐答案
您应该在端点中添加路径过滤器.
You should add a path filter in the endpoint.
普通网站集的路径类似于 https://tenant.sharepoint.com
,而个人(One Drive)网站集的路径类似于 https://tenant-my.sharepoint.com/personal/*
.
Normal site collections have a path like https://tenant.sharepoint.com
whereas personal (One Drive) site collections have path like https://tenant-my.sharepoint.com/personal/*
.
因此,修改您的端点如下:
So, modify your endpoint as below:
https://<site_name>.sharepoint.com/_api/search/query?querytext='contentclass:STS_Site
Path:"https://<site_name>.sharepoint.com/*"'&rowlimit=500
这只会返回以 https://<site_name>.sharepoint.com
路径开头的网站集,并将排除位于不同路径上的 One Drive 网站集.
This will only return site collections starting with https://<site_name>.sharepoint.com
path and will exclude the One Drive site collections which are on a different path.
这篇关于SharePoint 使用 SharePoint Online REST API 获取所有站点和所有子站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!