directoryObject: getByIds
命名空间:microsoft.graph
重要
Microsoft Graph版本下的 /beta API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
返回 ID 列表中指定的目录对象。
该函数的一些常见用途是:
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限。
| 权限类型 |
权限(从最低特权到最高特权) |
| 委派(工作或学校帐户) |
Directory.Read.All |
| 委派(个人 Microsoft 帐户) |
不支持。 |
| 应用程序 |
Directory.Read.All |
当应用程序查询返回 directoryObject 类型集合的关系时,如果它没有读取某种派生类型(如设备)的权限,则会返回该类型的成员,但返回的信息有限。 使用这种行为,应用程序可请求所需的最低特权权限,而不依赖于 Directory.* 集权限。 有关详细信息,请参阅为不可访问的成员对象返回有限的信息。
HTTP 请求
POST /directoryObjects/getByIds
| 名称 |
说明 |
| Authorization |
Bearer {token}。必需。 |
| Content-type |
application/json. Required. |
请求正文
在请求正文中,提供具有以下参数的 JSON 对象。
响应
如果成功,此方法在响应正文中返回 200 OK 响应代码和 String 集合对象。
示例
请求
POST https://graph.microsoft.com/beta/directoryObjects/getByIds
Content-type: application/json
{
"ids":["84b80893-8749-40a3-97b7-68513b600544","5d6059b6-368d-45f8-91e1-8e07d485f1d0"],
"types":["user"]
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var ids = new List<String>()
{
"84b80893-8749-40a3-97b7-68513b600544",
"5d6059b6-368d-45f8-91e1-8e07d485f1d0"
};
var types = new List<String>()
{
"user"
};
await graphClient.DirectoryObjects
.GetByIds(ids,types)
.Request()
.PostAsync();
const options = {
authProvider,
};
const client = Client.init(options);
const directoryObject = {
ids: ['84b80893-8749-40a3-97b7-68513b600544','5d6059b6-368d-45f8-91e1-8e07d485f1d0'],
types: ['user']
};
await client.api('/directoryObjects/getByIds')
.version('beta')
.post(directoryObject);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/directoryObjects/getByIds"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSMutableDictionary *payloadDictionary = [[NSMutableDictionary alloc] init];
NSMutableArray *idsList = [[NSMutableArray alloc] init];
[idsList addObject: @"84b80893-8749-40a3-97b7-68513b600544"];
[idsList addObject: @"5d6059b6-368d-45f8-91e1-8e07d485f1d0"];
payloadDictionary[@"ids"] = idsList;
NSMutableArray *typesList = [[NSMutableArray alloc] init];
[typesList addObject: @"user"];
payloadDictionary[@"types"] = typesList;
NSData *data = [NSJSONSerialization dataWithJSONObject:payloadDictionary options:kNilOptions error:&error];
[urlRequest setHTTPBody:data];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
LinkedList<String> idsList = new LinkedList<String>();
idsList.add("84b80893-8749-40a3-97b7-68513b600544");
idsList.add("5d6059b6-368d-45f8-91e1-8e07d485f1d0");
LinkedList<String> typesList = new LinkedList<String>();
typesList.add("user");
graphClient.directoryObjects()
.getByIds(DirectoryObjectGetByIdsParameterSet
.newBuilder()
.withIds(idsList)
.withTypes(typesList)
.build())
.buildRequest()
.post();
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.New()
requestBody.SetIds( []String {
"84b80893-8749-40a3-97b7-68513b600544",
"5d6059b6-368d-45f8-91e1-8e07d485f1d0",
}
requestBody.SetTypes( []String {
"user",
}
result, err := graphClient.DirectoryObjects().GetByIds().Post(requestBody)
Import-Module Microsoft.Graph.DirectoryObjects
$params = @{
Ids = @(
"84b80893-8749-40a3-97b7-68513b600544"
"5d6059b6-368d-45f8-91e1-8e07d485f1d0"
)
Types = @(
"user"
)
}
Get-MgDirectoryObjectById -BodyParameter $params
响应
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#directoryObjects",
"value": [
{
"@odata.type": "#microsoft.graph.user",
"id": "84b80893-8749-40a3-97b7-68513b600544",
"accountEnabled": true,
"displayName": "Trevor Jones"
},
{
"@odata.type": "#microsoft.graph.user",
"id": "84b80893-8749-40a3-97b7-68513b600544",
"accountEnabled": true,
"displayName": "Billy Smith"
}
]
}