命名空间:microsoft.graph
重要
Microsoft Graph /beta 版本下的 API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
检索 驱动器 资源的属性和关系。
驱动器是文件系统(如 OneDrive 或 SharePoint 文档库)的顶级容器。
此 API 可用于以下国家级云部署。
| 全局服务 |
美国政府 L4 |
美国政府 L5 (DOD) |
由世纪互联运营的中国 |
| ✅ |
✅ |
✅ |
✅ |
权限
为此 API 选择标记为最低特权的权限。
只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。
| 权限类型 |
最低特权权限 |
更高特权权限 |
| 委派(工作或学校帐户) |
Files.Read |
Files.Read.All, Files.ReadWrite, Files.ReadWrite.All、Sites.Read.All、Sites.ReadWrite.All、User.Read |
| 委派(个人 Microsoft 帐户) |
Files.Read |
Files.Read.All, Files.ReadWrite, Files.ReadWrite.All |
| 应用程序 |
不支持。 |
不支持。 |
HTTP 请求
获取用户的当前 OneDrive
可从单一实例访问 me 使用委派身份验证) 时登录用户的驱动器 (。
如果用户具有 OneDrive 许可证,但尚未设置其 OneDrive,则此请求将在使用委派身份验证时自动预配用户的驱动器。
GET /me/drive
获取用户的 OneDrive
若要访问用户的 OneDrive 或 OneDrive for Business,应用必须请求对 User 资源获取 drive 关系。
如果用户具有 OneDrive 许可证,但尚未设置其 OneDrive,则此请求将在使用委派身份验证时自动预配用户的驱动器。
GET /users/{idOrUserPrincipalName}/drive
路径参数
| 参数名称 |
值 |
说明 |
|
idOrUserPrincipalName |
string |
必需。 拥有 OneDrive 的用户对象的标识符。 |
获取与组关联的文档库
若要访问组的默认文档库,应用应请求组中的 drive 关系。
GET /groups/{groupId}/drive
路径参数
| 参数名称 |
值 |
说明 |
|
groupId |
string |
必填。 拥有文档库的组的标识符。 |
获取某个站点的文档库
若要访问站点的默认文档库,应用应请求站点中的 drive 关系。
GET /sites/{siteId}/drive
路径参数
| 参数名称 |
值 |
说明 |
|
siteId |
string |
必需。 包含文档库的站点的标识符。 |
根据 ID 获取驱动器
如果你有某个驱动器的唯一标识符,则可以直接从顶级驱动器集合来访问它。
GET /drives/{driveId}
路径参数
| 参数名称 |
值 |
说明 |
|
driveId |
string |
必需。 请求获取的驱动器的标识符。 |
可选的查询参数
这些方法支持 $select 查询参数 来形成响应。
响应
每个方法将在响应正文中返回匹配驱动器的 Drive 资源。
错误响应代码
如果驱动器不存在且无法自动预配,则在使用委派身份验证时 () 返回响应 HTTP 404 。
示例
示例 1:获取驱动器
请求
以下示例显示了一个请求。
// 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.Me.Drive.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
drive, err := graphClient.Me().Drive().Get(context.Background(), nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Drive result = graphClient.me().drive().get();
const options = {
authProvider,
};
const client = Client.init(options);
let drive = await client.api('/me/drive')
.version('beta')
.get();
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$result = $graphServiceClient->me()->drive()->get()->wait();
Import-Module Microsoft.Graph.Beta.Files
# A UPN can also be used as -UserId.
Get-MgBetaUserDefaultDrive -UserId $userId
# 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.me.drive.get()
响应
以下示例显示了相应的响应。
HTTP/1.1 200 OK
Content-type: application/json
{
"id": "b!t18F8ybsHUq1z3LTz8xvZqP8zaSWjkFNhsME-Fepo75dTf9vQKfeRblBZjoSQrd7",
"driveType": "business",
"owner": {
"user": {
"id": "efee1b77-fb3b-4f65-99d6-274c11914d12",
"displayName": "Ryan Gregg"
}
},
"quota": {
"deleted": 256938,
"remaining": 1099447353539,
"state": "normal",
"total": 1099511627776
}
}
示例 2:获取驱动器及其设置
默认情况下不返回 设置 属性。 下面的示例用于 $select 在响应中显式请求它。
请求
以下示例显示了一个请求。
GET /drives/b!t18F8ybsHUq1z3LTz8xvZqP8zaSWjkFNhsME-Fepo75dTf9vQKfeRblBZjoSQrd7?$select=id,settings
// 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.Drives["{drive-id}"].GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Select = new string []{ "id","settings" };
});
// 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"
graphdrives "github.com/microsoftgraph/msgraph-beta-sdk-go/drives"
//other-imports
)
requestParameters := &graphdrives.DriveItemRequestBuilderGetQueryParameters{
Select: [] string {"id","settings"},
}
configuration := &graphdrives.DriveItemRequestBuilderGetRequestConfiguration{
QueryParameters: requestParameters,
}
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
drives, err := graphClient.Drives().ByDriveId("drive-id").Get(context.Background(), configuration)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Drive result = graphClient.drives().byDriveId("{drive-id}").get(requestConfiguration -> {
requestConfiguration.queryParameters.select = new String []{"id", "settings"};
});
const options = {
authProvider,
};
const client = Client.init(options);
let drive = await client.api('/drives/b!t18F8ybsHUq1z3LTz8xvZqP8zaSWjkFNhsME-Fepo75dTf9vQKfeRblBZjoSQrd7')
.version('beta')
.select('id,settings')
.get();
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Drives\Item\DriveItemRequestBuilderGetRequestConfiguration;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestConfiguration = new DriveItemRequestBuilderGetRequestConfiguration();
$queryParameters = DriveItemRequestBuilderGetRequestConfiguration::createQueryParameters();
$queryParameters->select = ["id","settings"];
$requestConfiguration->queryParameters = $queryParameters;
$result = $graphServiceClient->drives()->byDriveId('drive-id')->get($requestConfiguration)->wait();
Import-Module Microsoft.Graph.Beta.Files
Get-MgBetaDrive -DriveId $driveId -Property "id,settings"
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.drives.item.drive_item_request_builder import DriveItemRequestBuilder
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 = DriveItemRequestBuilder.DriveItemRequestBuilderGetQueryParameters(
select = ["id","settings"],
)
request_configuration = RequestConfiguration(
query_parameters = query_params,
)
result = await graph_client.drives.by_drive_id('drive-id').get(request_configuration = request_configuration)
响应
以下示例显示了相应的响应。
HTTP/1.1 200 OK
Content-type: application/json
{
"id": "b!t18F8ybsHUq1z3LTz8xvZqP8zaSWjkFNhsME-Fepo75dTf9vQKfeRblBZjoSQrd7",
"settings": {
"itemDefaultSensitivityLabelId": "bf7ea563-b848-4ec8-9155-b2054564cfe4"
}
}