[英]How to get group names of the user is a member of using Microsoft Graph API?
I want to know the list of groups the user is a member of in AAD.我想知道用户在 AAD 中所属的组列表。 Based on the membership of the group they can do another function. To achieve this I used the MS Graph API, but I get only group Ids, not the group names.
根据组的成员身份,他们可以做另一个 function。为此,我使用了 MS Graph API,但我只获得组 ID,而不是组名称。 I used the following two ways using graph API. The first method used,
我使用图 API 使用了以下两种方法。第一种方法使用,
await graphClient.Users[upn].GetMemberGroups(false).Request().PostAsync()
response:回复:
[ "fee2c45b-915a-4a64-b130-f4eb9e75525e", "4fe90ae7-065a-478b-9400-e0a0e1cbd540", "e0c3beaf-eeb4-43d8-abc5-94f037a65697" ]
The second method used,使用的第二种方法,
await graphClient.Users[upn].MemberOf.Request().GetAsync();
response:回复:
[
{
"deletedDateTime": null,
"id": "1c4934554-5006-403a-bf4f-bsdfeerwfs6fe6f",
"oDataType": "#microsoft.graph.group",
"additionalData": {
"creationOptions": [],
"isAssignableToRole": null,
"resourceBehaviorOptions": [],
"resourceProvisioningOptions": []
}
},
{
"deletedDateTime": null,
"id": "f8975c2f-7651d-4f3a-1234-4ec3808a0ac2",
"oDataType": "#microsoft.graph.group",
"additionalData": {
"creationOptions": [
[]
],
"isAssignableToRole": null,
"resourceBehaviorOptions": [],
"resourceProvisioningOptions": [
[]
]
}
}
]
What I need is along with the group name and group ID.我需要的是组名和组 ID。 How do I get both together in an efficient way?
我如何以有效的方式将两者结合在一起? Or are there any other method which i can try for this purpose?
或者还有其他方法可以尝试吗?
For me the following works for getting group names:对我来说,以下是获取组名的方法:
var page = await graphClient
.Users[userObjectId]
.MemberOf
.Request()
.GetAsync();
var names = new List<string>();
names.AddRange(page
.OfType<Group>()
.Select(x => x.DisplayName)
.Where(name => !string.IsNullOrEmpty(name)));
while (page.NextPageRequest != null)
{
page = await page.NextPageRequest.GetAsync();
names.AddRange(page
.OfType<Group>()
.Select(x => x.DisplayName)
.Where(name => !string.IsNullOrEmpty(name)));
}
return names;
There should be a DisplayName/displayName in the response for groups.组的响应中应该有一个 DisplayName/displayName。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.