directoryObject: getMemberGroups
本文内容
命名空间:microsoft.graph
返回指定的用户、组、服务主体、组织联系人、设备或 目录对象是其中一个成员的 组的所有组 ID。 此函数是可传递的。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限 。
目录对象的组成员身份
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
User.ReadBasic.All 和 GroupMember.Read.All、User.Read.All 和 GroupMember.Read.All、User.ReadBasic.All 和 Group.Read.All、User.Read.All 和 Group.Read.All、Directory.Read.All
委派(个人 Microsoft 帐户)
不支持。
应用程序
User.Read.All 和 GroupMember.Read.All、User.Read.All 和 Group.Read.All、Directory.Read.All
用户的组成员身份
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
User.ReadBasic.All 和 GroupMember.Read.All、User.Read.All 和 GroupMember.Read.All、User.ReadBasic.All 和 Group.Read.All、User.Read.All 和 Group.Read.All、Directory.Read.All
委派(个人 Microsoft 帐户)
不支持。
应用程序
User.Read.All 和 GroupMember.Read.All、User.Read.All 和 Group.Read.All、Directory.Read.All
组的组成员身份
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
GroupMember.Read.All, Group.Read.All, Directory.Read.All, Group.ReadWrite.All, Directory.ReadWrite.All
委派(个人 Microsoft 帐户)
不支持。
应用程序
GroupMember.Read.All, Group.Read.All, Directory.Read.All, Group.ReadWrite.All, Directory.ReadWrite.All
服务主体的组成员身份
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
Application.Read.All、Directory.Read.All、Application.ReadWrite.All、Directory.ReadWrite.All
委派(个人 Microsoft 帐户)
不支持。
应用程序
Application.Read.All、Directory.Read.All、Application.ReadWrite.All、Directory.ReadWrite.All
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
Directory.Read.All、Directory.ReadWrite.All
委派(个人 Microsoft 帐户)
不支持。
应用程序
Directory.Read.All、Directory.ReadWrite.All
设备的组成员身份
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
Device.Read.All、Directory.Read.All、Directory.ReadWrite.All
委派(个人 Microsoft 帐户)
不支持。
应用程序
Device.Read.All、Device.ReadWrite.All、Directory.Read.All、Directory.ReadWrite.All
HTTP 请求
目录对象的组成员身份 (用户、组、服务主体或组织联系人) 。
POST /directoryObjects/{id}/getMemberGroups
已登录用户或其他用户的组成员身份。
POST /me/getMemberGroups
POST /users/{id | userPrincipalName}/getMemberGroups
组的组成员身份。
POST /groups/{id}/getMemberGroups
服务主体的组成员身份。
POST /servicePrincipals/{id}/getMemberGroups
组织联系人的组成员身份。
POST /contacts/{id}/getMemberGroups
设备的组成员身份。
POST /devices/{id}/getMemberGroups
名称
说明
Authorization
Bearer {token}。必需。
Content-Type
application/json
请求正文
在请求正文中,提供具有以下参数的 JSON 对象。
参数
类型
说明
securityEnabledOnly
Boolean
true 指定仅返回实体是成员的安全组; false 指定应返回实体是成员的所有组和目录角色。 true 只能为用户和服务主体指定 ,以返回启用安全保护的组。
响应
如果成功,此方法在响应正文中返回 200 OK 响应代码和 String 集合对象。
示例
示例 1:检查目录对象的组成员身份
请求
POST https://graph.microsoft.com/v1.0/directoryObjects/0049d944-a805-4680-9f54-3ab292090309/getMemberGroups
Content-type: application/json
{
"securityEnabledOnly": false
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var securityEnabledOnly = false;
await graphClient.DirectoryObjects["{directoryObject-id}"]
.GetMemberGroups(securityEnabledOnly)
.Request()
.PostAsync();
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
const options = {
authProvider,
};
const client = Client.init(options);
const string = {
securityEnabledOnly: false
};
await client.api('/directoryObjects/0049d944-a805-4680-9f54-3ab292090309/getMemberGroups')
.post(string);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/directoryObjects/0049d944-a805-4680-9f54-3ab292090309/getMemberGroups"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSMutableDictionary *payloadDictionary = [[NSMutableDictionary alloc] init];
BOOL securityEnabledOnly = NO;
payloadDictionary[@"securityEnabledOnly"] = securityEnabledOnly;
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];
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Boolean securityEnabledOnly = false;
graphClient.directoryObjects("0049d944-a805-4680-9f54-3ab292090309")
.getMemberGroups(DirectoryObjectGetMemberGroupsParameterSet
.newBuilder()
.withSecurityEnabledOnly(securityEnabledOnly)
.build())
.buildRequest()
.post();
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewSecurityEnabledOnlyRequestBody()
securityEnabledOnly := false
requestBody.SetSecurityEnabledOnly(&securityEnabledOnly)
directoryObjectId := "directoryObject-id"
result, err := graphClient.DirectoryObjectsById(&directoryObjectId).GetMemberGroups(directoryObject-id).Post(requestBody)
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
Import-Module Microsoft.Graph.DirectoryObjects
$params = @{
SecurityEnabledOnly = $false
}
Get-MgDirectoryObjectMemberGroup -DirectoryObjectId $directoryObjectId -BodyParameter $params
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
响应
下面是一个响应示例
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(Edm.String)",
"value": [
"a8daa1fb-d24c-47d0-9e9e-c99e83394e3e"
]
}
示例 2:检查已登录用户的组成员身份
请求
POST https://graph.microsoft.com/v1.0/me/getMemberGroups
Content-type: application/json
{
"securityEnabledOnly": true
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var securityEnabledOnly = true;
await graphClient.Me
.GetMemberGroups(securityEnabledOnly)
.Request()
.PostAsync();
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
const options = {
authProvider,
};
const client = Client.init(options);
const string = {
securityEnabledOnly: true
};
await client.api('/me/getMemberGroups')
.post(string);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/me/getMemberGroups"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSMutableDictionary *payloadDictionary = [[NSMutableDictionary alloc] init];
BOOL securityEnabledOnly = YES;
payloadDictionary[@"securityEnabledOnly"] = securityEnabledOnly;
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];
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Boolean securityEnabledOnly = true;
graphClient.me()
.getMemberGroups(DirectoryObjectGetMemberGroupsParameterSet
.newBuilder()
.withSecurityEnabledOnly(securityEnabledOnly)
.build())
.buildRequest()
.post();
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewSecurityEnabledOnlyRequestBody()
securityEnabledOnly := true
requestBody.SetSecurityEnabledOnly(&securityEnabledOnly)
result, err := graphClient.Me().GetMemberGroups().Post(requestBody)
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
Import-Module Microsoft.Graph.Users.Actions
$params = @{
SecurityEnabledOnly = $true
}
# A UPN can also be used as -UserId.
Get-MgUserMemberGroup -UserId $userId -BodyParameter $params
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
响应
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(Edm.String)",
"value": [
"6239671a-0db6-4e8b-9d2f-f280efb5a181",
"2e2f1227-1586-45ae-bf51-fccc1de72625",
"1dae9306-be75-4c3c-99ec-0316a4342c84",
"0e2d1bbb-76f8-4140-bda7-2a858b74507e",
"0049d944-a805-4680-9f54-3ab292090309",
"a8daa1fb-d24c-47d0-9e9e-c99e83394e3e",
"6f204729-1b8f-4067-bcc9-98fb6c069ffd",
"59afd38d-441a-4358-b074-8b9b1e7de52f",
"64ed3df3-53c7-4d4d-ac5c-5c8dd4dafe33",
"8b676bab-4b1e-419e-a253-7f5aca97d739",
"be4ef325-9fa8-40d7-b375-4758853ddf52",
"f5987b5a-61f6-4c31-9fa2-7bfb845c8d2a"
]
}