命名空间:microsoft.graph
重要
Microsoft Graph /beta 版本下的 API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
列出组织中的所有可用 站点 。
还支持特定的筛选条件和查询选项,如下所述:
| Filter 语句 |
Select 语句 |
说明 |
siteCollection/root ne null |
siteCollection,webUrl |
Lists组织中的所有根级网站集。 对于发现每个地理位置的主站点非常有用。 |
此外,可以对集合使用 $search 查询来 /sites 查找与给定关键字匹配的网站。
如果要列出所有地理位置中的所有站点,请参阅 getAllSites。
有关生成使用站点发现进行扫描的应用程序的更多指南,请参阅发现 文件和大规模检测更改的最佳做法。
此 API 可用于以下国家级云部署。
| 全局服务 |
美国政府 L4 |
美国政府 L5 (DOD) |
由世纪互联运营的中国 |
| ✅ |
✅ |
✅ |
✅ |
权限
要调用此 API,需要以下权限之一。 若要了解详细信息,包括如何选择权限的信息,请参阅权限。
列出所有网站集
| 权限类型 |
权限(从最低特权到最高特权) |
| 委派(工作或学校帐户) |
不支持。 |
| 委派(个人 Microsoft 帐户) |
不支持。 |
| 应用程序 |
Sites.Read.All、Sites.ReadWrite.All |
发现每个地理位置的主站点
| 权限类型 |
权限(从最低特权到最高特权) |
| 委派(工作或学校帐户) |
Sites.Read.All、Sites.ReadWrite.All |
| 委派(个人 Microsoft 帐户) |
不支持。 |
| 应用程序 |
Sites.Read.All、Sites.ReadWrite.All |
HTTP 请求
列出组织中的所有可用站点:
GET /sites
列出组织中的所有根级网站集:
GET /sites?$filter=siteCollection/root ne null
示例
请求
GET https://graph.microsoft.com/beta/sites?$select=siteCollection,webUrl&$filter=siteCollection/root%20ne%20null
// Code snippets are only available for the latest version. Current version is 5.x
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Sites.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Select = new string []{ "siteCollection","webUrl" };
requestConfiguration.QueryParameters.Filter = "siteCollection/root ne null";
});
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphsites "github.com/microsoftgraph/msgraph-beta-sdk-go/sites"
//other-imports
)
requestFilter := "siteCollection/root ne null"
requestParameters := &graphsites.SitesRequestBuilderGetQueryParameters{
Select: [] string {"siteCollection","webUrl"},
Filter: &requestFilter,
}
configuration := &graphsites.SitesRequestBuilderGetRequestConfiguration{
QueryParameters: requestParameters,
}
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
sites, err := graphClient.Sites().Get(context.Background(), configuration)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
SiteCollectionResponse result = graphClient.sites().get(requestConfiguration -> {
requestConfiguration.queryParameters.select = new String []{"siteCollection", "webUrl"};
requestConfiguration.queryParameters.filter = "siteCollection/root ne null";
});
const options = {
authProvider,
};
const client = Client.init(options);
let sites = await client.api('/sites')
.version('beta')
.filter('siteCollection/root ne null')
.select('siteCollection,webUrl')
.get();
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Sites\SitesRequestBuilderGetRequestConfiguration;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestConfiguration = new SitesRequestBuilderGetRequestConfiguration();
$queryParameters = SitesRequestBuilderGetRequestConfiguration::createQueryParameters();
$queryParameters->select = ["siteCollection","webUrl"];
$queryParameters->filter = "siteCollection/root ne null";
$requestConfiguration->queryParameters = $queryParameters;
$result = $graphServiceClient->sites()->get($requestConfiguration)->wait();
Import-Module Microsoft.Graph.Beta.Sites
Get-MgBetaSite -Property "siteCollection,webUrl" -Filter "siteCollection/root ne null"
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.sites.sites_request_builder import SitesRequestBuilder
from kiota_abstractions.base_request_configuration import RequestConfiguration
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
query_params = SitesRequestBuilder.SitesRequestBuilderGetQueryParameters(
select = ["siteCollection","webUrl"],
filter = "siteCollection/root ne null",
)
request_configuration = RequestConfiguration(
query_parameters = query_params,
)
result = await graph_client.sites.get(request_configuration = request_configuration)
响应
HTTP/1.1 200 OK
Content-type: application/json
{
"value": [
{
"id": "contoso.sharepoint.com,da60e844-ba1d-49bc-b4d4-d5e36bae9019,712a596e-90a1-49e3-9b48-bfa80bee8740",
"name": "Contoso USA",
"root": { },
"siteCollection": {
"hostname": "contoso.sharepoint.com",
"dataLocationCode": "NAM",
"root": { }
},
"webUrl": "https://contoso.sharepoint.com"
},
{
"id": "contoso-jpn.sharepoint.com,da60e844-ba1d-49bc-b4d4-d5e36bae9019,0271110f-634f-4300-a841-3a8a2e851851",
"name": "Contoso Japan",
"root": { },
"siteCollection": {
"hostname": "contoso-jp.sharepoint.com",
"dataLocationCode": "JPN",
"root": { }
},
"webUrl": "https://contoso-jp.sharepoint.com"
}
]
}
请求
// Code snippets are only available for the latest version. Current version is 5.x
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Sites.GetAsync();
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
//other-imports
)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
sites, err := graphClient.Sites().Get(context.Background(), nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
SiteCollectionResponse result = graphClient.sites().get();
const options = {
authProvider,
};
const client = Client.init(options);
let sites = await client.api('/sites')
.version('beta')
.get();
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$result = $graphServiceClient->sites()->get()->wait();
Import-Module Microsoft.Graph.Beta.Sites
Get-MgBetaSite
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
result = await graph_client.sites.get()
响应
HTTP/1.1 200 OK
Content-type: application/json
{
"value": [
{
"id": "contoso.sharepoint.com,bf6fb551-d508-4946-a439-b2a6154fc1d9,65a04b8b-1f44-442b-a1fc-9e5852fb946c",
"name": "Root Site",
"root": { },
"siteCollection": {
"hostname": "contoso.sharepoint.com",
"dataLocationCode": "NAM",
"root": { }
},
"webUrl": "https://contoso.sharepoint.com"
},
{
"id": "contoso.sharepoint.com,d9ecf079-9b13-4376-ac5d-f242dda55626,746dbcc1-fa2b-4120-b657-2670bae5bb6f",
"name": "Site A",
"root": { },
"siteCollection": {
"hostname": "contoso.sharepoint.com"
},
"webUrl": "https://contoso.sharepoint.com/sites/siteA"
},
{
"id": "contoso.sharepoint.com,fd1a778f-263e-4c43-acdf-d5c2519d80eb,c06016db-dfec-4f79-83a1-09c6dbfd7022",
"name": "Site B",
"root": { },
"siteCollection": {
"hostname": "contoso.sharepoint.com"
},
"webUrl": "https://contoso.sharepoint.com/sites/siteB"
}
]
}