简体   繁体   English

如何获取用户的组名是使用 Microsoft Graph API 的成员?

[英]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.

相关问题 如何使用 Microsoft Graph API 获取所有组的用户名? - How to get user names of all groups using Microsoft Graph API? 如何使用 Microsoft Graph API 从包含嵌套组的组中仅获取用户? - How to get only User's from a Group that contains nested Groups using Microsoft Graph API? 如何使用 Microsoft Graph api 或类似的 API 获取联系人组 - how to get contact group using Microsoft Graph api or similier apis 使用 azure 图 api 获取具有用户所属组 id 的所有用户的列表 - Get list of all users with the id of group in which user is member using azure graph api 如何使用 Microsoft Graph api 从 azure 活动目录中获取所有用户属性 - How to get all user attributes from azure active directory using Microsoft Graph api c# 如何使用 Microsoft Graph API 获取 Office 365 用户照片 - c# how to get office 365 user photo using microsoft graph api Microsoft AAD 组 - 使用 Microsoft Graph 获取“组”类型的成员 - Microsoft AAD Group - get members of 'group' type using Microsoft Graph 使用Microsoft Graph .NET Client Library从组中删除成员 - Remove a member from a group using Microsoft Graph .NET Client Library 如何使用 Microsoft.Graph 与登录用户共享日历 - how to get calendars shared with logged in user using Microsoft.Graph 在 Microsoft Graph API 中查找特定用户的组名时出现问题 - Issue in finding Group name of specific user in Microsoft Graph API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM