![](/img/trans.png)
[英]How to get user names of all groups using Microsoft Graph API?
[英]Microsoft Graph: Get Children of all Child Groups (.NET)
我在 .NET Blazor 項目中使用 Graph API 來獲取組的所有成員。 除非該組有其他組作為成員而不僅僅是用戶,否則它會很好地工作。 我正在使用的代碼如下:
var groups = await GraphServiceClient.Groups.Request()
.Filter($"mail+eq+'{email}'")
.Expand("members")
.GetAsync(); //get the member groups by email, then include member information
var members = groups.FirstOrDefault().Members.ToList(); //get the first group (there should be only one) and convert it to list
return members.Select(s => ((User)s).DisplayName).ToList(); //cast the items to User and get the display name, then return this list
當我嘗試將組投射到用戶時失敗。 當然,我可以使用.Where
過濾掉組,但是我會錯過它們包含的用戶。
我怎樣才能獲得所有子組的成員(盡可能多的級別)並一次返回它們?
您想要做的就是所謂的“遞歸”,當您使用嵌套對象時,它應該是您的默認搜索詞。 您可以編寫自己的遞歸 function,或嘗試使用 Linq 遞歸。 它們有點難以處理,但最終非常有用。
但是,似乎 API 已經包含一個名為“transitiveMembers”的 function,這可能是您正在尋找的:
注意:我不知道 API 調用的返回格式,但看起來它必須被過濾,因為它將包括嵌套的組對象、設備等。 我還想說的是,在這種情況下,我相信“成員”類似於 class 成員,而不是每個組的實際用戶成員。
你介意分享解決方案嗎_
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.