简体   繁体   English

如何使用 Microsoft Graph API 获取所有组的用户名?

[英]How to get user names of all groups using Microsoft Graph API?

I want to read all member names of all groups using Graph API我想使用 Graph API 读取所有组的所有成员名称

My Method我的方法

var unternehmen = await graphManager
    .Client
    .Groups
    .Request()
    .Expand("members")
    .GetAsync();

foreach (var gruppe in unternehmen)
{
    Debug.Log("  " + gruppe.Id + " " + gruppe.DisplayName);

    foreach (var member in gruppe.Members)
    {
         Debug.Log(member.Id);
    }         
}

Response回复

Only Member ID's and all Group Names只有成员 ID 和所有组名

What I need is all names of all groups.我需要的是所有组的所有名称。 How can I get those?我怎样才能得到那些?

You need to caste the members to Microsoft.Graph.User first because not all members are users.您需要先将成员强制转换为Microsoft.Graph.User ,因为并非所有成员都是用户。

GET https://graph.microsoft.com/v1.0/groups/{id}/members/microsoft.graph.user

C# code: C# 代码:

var groups = await graphClient.Groups
    .Request()
    .Expand("members")
    .GetAsync();

foreach (var gruppe in groups)
{
    Console.WriteLine($"{gruppe.Id}, {gruppe.DisplayName}");

    // another method to get members
    // var members = await graphClient.Groups[gruppe.Id].Members.Request().GetAsync();
    
    var members = gruppe.Members;
    var userMembers = members.Where(m => m.ODataType == "#microsoft.graph.user").Cast<User>();
    foreach (User user in userMembers)
    {
        Console.WriteLine($"{user.Id}, {user.DisplayName}");
    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取用户的组名是使用 Microsoft Graph API 的成员? - How to get group names of the user is a member of 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 从 azure 活动目录中获取所有用户属性 - How to get all user attributes from azure active directory using Microsoft Graph api 如何使用Microsoft Graph API按通讯组列表电子邮件过滤组? - How to filter Groups by Distribution List Email using Microsoft Graph API? 仅使用 Microsoft Graph 获取根组 - Get root groups only using Microsoft Graph "在 c# 中使用 Microsoft Graph API 获取所有电子邮件" - Get all email message using Microsoft Graph API in c# 如何使用 Microsoft Graph SDK 获取 AD 用户组列表以及 AD 用户 - How can I get a list of AD user groups along with AD user with Microsoft Graph SDK c# 如何使用 Microsoft Graph API 获取 Office 365 用户照片 - c# how to get office 365 user photo using microsoft graph api 如何在不需要管理员权限的情况下访问Microsoft Graph API中已登录用户的组? - How can I access the signed in user's groups in Microsoft's Graph API without needing admin priviledges? 如何使用Microsoft Graph API正确获取与我共享的所有项目? - How to correctly get all the items shared with me using Microsoft Graph API?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM