获取网站资源
本文内容
命名空间:microsoft.graph
重要
Microsoft Graph版本下的 /beta API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
检索 网站 资源的属性和关系。网站 资源表示 SharePoint 中的团队网站。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限 。
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
Sites.Read.All、Sites.ReadWrite.All
委派(个人 Microsoft 帐户)
不支持。
应用程序
Sites.Read.All、Sites.ReadWrite.All
获取租户的根网站
若要访问租户内的根 SharePoint 网站:
GET /sites/root
GET /sites/contoso.sharepoint.com
通过相对于服务器的 URL 访问网站
如果你的服务器具有 网站 资源的相对于服务器的 URL,你可以构建请求,如下所示:
GET /sites/{hostname}:/{server-relative-path}
访问组团队网站
若要访问组的团队网站:
GET /groups/{group-id}/sites/root
示例
请求
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var site = await graphClient.Sites["{site-id}"]
.Request()
.GetAsync();
const options = {
authProvider,
};
const client = Client.init(options);
let site = await client.api('/sites/{site-id}')
.version('beta')
.get();
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/sites/{site-id}"]]];
[urlRequest setHTTPMethod:@"GET"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
MSGraphSite *site = [[MSGraphSite alloc] initWithData:data error:&nserror];
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Site site = graphClient.sites("{site-id}")
.buildRequest()
.get();
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
siteId := "site-id"
result, err := graphClient.SitesById(&siteId).Get(nil)
Import-Module Microsoft.Graph.Sites
Get-MgSite -SiteId $siteId
响应
HTTP/1.1 200 OK
Content-type: application/json
{
"id": "contoso.sharepoint.com,2C712604-1370-44E7-A1F5-426573FDA80A,2D2244C3-251A-49EA-93A8-39E1C3A060FE",
"owner": {
"user": {
"displayName": "Daron Spektor",
"id": "5280E7FE-DC7A-4486-9490-E790D81DFEB3"
}
},
"displayName": "OneDrive Team Site",
"name": "1drvteam",
"createdDateTime": "2017-05-09T20:56:00Z",
"lastModifiedDateTime": "2017-05-09T20:56:01Z",
"webUrl": "https://contoso.sharepoint.com/teams/1drvteam"
}