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

SharePoint使用SharePoint online REST API获取所有站点和所有子站点,sharepoint,sharepoint-online,sharepoint-rest-api,Sharepoint,Sharepoint Online,Sharepoint Rest Api,对于SharePoint Online connector,我们使用以下步骤获取所有站点: 步骤1:在SharePoint实例上创建具有以下权限的加载项xml <AppPermissionRequests> <AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl"/> <AppPermissionRequest Scope="h

对于SharePoint Online connector,我们使用以下步骤获取所有站点:

步骤1:在SharePoint实例上创建具有以下权限的加载项xml

<AppPermissionRequests>
        <AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl"/>
        <AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="Read"/>
</AppPermissionRequests>
步骤2:在API下面使用以获取所有站点和子站点

https://<site_name>.sharepoint.com/_api/search/query?querytext='contentclass:STS_Site' &rowlimit=100
我们面临的问题-

上面的端点将返回所有站点、子站点以及用户的 个人站点一个驱动器,而我们需要所有站点和子站点 只有 请建议阅读所有网站、所有子网站、所有文件夹和文件元数据所需的最低权限 我们提到了以下链接:


乔尔·德苏扎的一条路供你参考

1.第一个Ajax是获取根站点标题和相对URL

2.第二个AJAX是获取根站点下的所有子站点

3.这是一个递归函数,用于循环子站点并检查更多子站点


更多信息:

您应该在端点中添加路径筛选器

普通网站集的路径类似于https://tenant.sharepoint.com 而个人单驱网站集具有类似路径https://tenant-my.sharepoint.com/personal/*

因此,请按如下所示修改端点:

https://<site_name>.sharepoint.com/_api/search/query?querytext='contentclass:STS_Site
Path:"https://<site_name>.sharepoint.com/*"'&rowlimit=500
这将仅返回以开头的网站集https://.sharepoint.com 路径,将排除位于不同路径上的单驱动器网站集

https://yoursharepointsite.com/_api/search/query?querytext='(contentclass:STS_Site) (contentclass:STS_Web)'&trimduplicates=false&rowlimit=5000&selectproperties='Title,Url,Path,ParentLink'"

上面的RESTURL应该提供用户有权访问的所有站点和子站点。您可能需要修剪重复项。

我不想为此使用多个API。按照@gautam的建议,我能够得到预期的结果。谢谢你的回答谢谢Gautam你能帮我更正一下外接程序许可部分吗。我只需要设置读取权限。请检查更新的问题,如果只是为了显示/检索,那么阅读权限就足够了。但是如果你需要对它进行更多的处理,那么你将需要更高的权限,它只用于/检索。我认为以下权限就足够了。如果我错了,请纠正我
function getSubSites(SubSiteUrl, SubSiteTitle) {
    console.log(SubSiteUrl);
    $.ajax({
        url: _spPageContextInfo.siteAbsoluteUrl + SubSiteUrl + "/_api/web/webinfos?$select=ServerRelativeUrl,Title",
        method: "GET",
        headers: {
            "Accept": "application/json; odata=verbose"
        },
        success: function(subsites) {

            $.each(subsites.d.results, function(index) {
                getSubSites(this.ServerRelativeUrl, this.Title);
            });
        },
        error: function(subsites) {},
        async: false
    });
}
https://<site_name>.sharepoint.com/_api/search/query?querytext='contentclass:STS_Site
Path:"https://<site_name>.sharepoint.com/*"'&rowlimit=500
https://yoursharepointsite.com/_api/search/query?querytext='(contentclass:STS_Site) (contentclass:STS_Web)'&trimduplicates=false&rowlimit=5000&selectproperties='Title,Url,Path,ParentLink'"