如何使用 Microsoft Graph API 查找所有站点

fei*_*i0x 1 sharepoint sharepoint-online microsoft-graph-api

我正在寻找一个 Graph API 调用,它可以将 Sharepoint Online 中的所有站点返回给我。

查看枚举站点:https : //docs.microsoft.com/en-us/graph/api/site-list? view = graph-rest-beta & tabs =http

GET https://graph.microsoft.com/beta/sites?filter=siteCollection/root ne null
Run Code Online (Sandbox Code Playgroud)

它似乎没有返回基于组的站点或子站点。

查看站点搜索:https : //docs.microsoft.com/en-us/graph/api/site-search?view=graph-rest-beta&tabs=http

GET https://graph.microsoft.com/beta/sites?search={query}
Run Code Online (Sandbox Code Playgroud)

这可能更有希望,但没有解释“查询”应该如何构建或搜索什么。

我的想法是,由于所有站点 ID 都以租户域开头,因此我可以搜索该域,然后检索租户的每个站点和子站点。但我不确定如何执行该查询。

理想情况下是这样的:

GET https://graph.microsoft.com/beta/sites?search=id like contoso.microsoft.com
Run Code Online (Sandbox Code Playgroud)

fei*_*i0x 7

我发现这篇文章提出了一个非常相似的问题。

https://sharepoint.stackexchange.com/questions/230187/retrieve-all-sites-and-all-subsites-from-the-sharepoint-rest-api

'dvdsmpsn' 有一个回应,他分享说你可以通过这个调用检索所有站点:

https://graph.microsoft.com/v1.0/sites?search=*
Run Code Online (Sandbox Code Playgroud)

有趣的是,这在图形 API 的测试版中不起作用(此时)。

这实现了我想要的,所以我将其作为答案发布,但它并没有完全回答应该如何格式化搜索的问题,因此如果可以的话,我会将这个问题留给其他人回答。