对于SharePoint Online连接器,我们使用以下步骤来获取所有网站:
步骤1:在具有以下权限xml的SharePoint实例上创建加载项
<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
我们面临的问题 –
sites, sub sites along with user’s
personal site(One drive)
,而我们需要全部sites and sub sites
我们引用了以下链接:
答案 0 :(得分:1)
您应该在端点中添加路径过滤器。
普通网站集的路径类似于https://tenant.sharepoint.com
,而个人(One Drive)网站集的路径类似于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://<site_name>.sharepoint.com
路径开头的网站集,并将排除位于不同路径的One Drive网站集。
答案 1 :(得分:0)
乔尔·杜萨(Joel Dsouza)供您参考。
1。第一个Ajax是获取根站点标题和相对URL。
$.ajax({
url: _spPageContextInfo.siteAbsoluteUrl + "/_api/site/rootweb?$select=Title,ServerRelativeUrl",
method: "GET",
headers: {
"Accept": "application/json; odata=verbose"
},
success: function(rootsite) {
},
error: function(rootsite) {},
async: false
});
2。第二个AJAX是将所有子站点都置于“根站点”下。
$.ajax({
url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/webinfos?$select=ServerRelativeUrl,Title",
method: "GET",
headers: {
"Accept": "application/json; odata=verbose"
},
success: function(subsites) {
$.each(subsites.d.results, function() {
getSubSites(this.ServerRelativeUrl, this.Title);
});
},
error: function(subsites) {},
async: false
});
3。这是一个递归功能,可循环浏览子站点并检查更多子站点。
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
});
}
答案 2 :(得分:0)
https://yoursharepointsite.com/_api/search/query?querytext='(contentclass:STS_Site) (contentclass:STS_Web)'&trimduplicates=false&rowlimit=5000&selectproperties='Title,Url,Path,ParentLink'"
上面的剩余URL应该为您提供用户有权访问的所有站点和子站点。您可能需要修剪重复项。