C# 如何使用MS Graph API获取组织中的所有部门

C# 如何使用MS Graph API获取组织中的所有部门,c#,azure-active-directory,microsoft-graph-api,C#,Azure Active Directory,Microsoft Graph Api,我使用以下代码查找部门名称:- GraphServiceClient GraphServiceClient=connectToGraphAPIGlobals.adTenantId、Globals.adClientId、Globals.adClientSecret var Peoples = await graphServiceClient.Users[userid].People.Request().GetAsync(); foreach (Person Peop

我使用以下代码查找部门名称:-

GraphServiceClient GraphServiceClient=connectToGraphAPIGlobals.adTenantId、Globals.adClientId、Globals.adClientSecret

        var Peoples = await graphServiceClient.Users[userid].People.Request().GetAsync();
        foreach (Person People in Peoples)
        {
            if (People.DisplayName != null && People.DisplayName.Equals(userName))
            {
                return People.Department.ToString();

            }
        }

但是,我希望获得组织中所有部门的列表,而不是查找特定用户的部门。请提供帮助。

就像@Matt.G所说的,部门是用户配置文件页面上“职务信息”部分下的字符串值。没有列出组织中所有部门的api。您需要通过用户循环获取departmentName。

请查看Hi@Matt.G,但此代码正在通过用户循环,我已经有一个代码可以通过用户循环获取departmentName。但是,我想在不使用用户循环的情况下获取departmentName。Department是用户配置文件页面上作业信息部分下的字符串值。换句话说,它只是用户配置文件上的一个字符串属性,就像职务一样。。