与Microsoft.Azure.ActiveDirectory.GraphClient相比,调用Microsoft.Graph时用户的数据内容不足 [英] No Sufficient Data Content of User When Calling Microsoft.Graph Compared to Microsoft.Azure.ActiveDirectory.GraphClient

查看:80
本文介绍了与Microsoft.Azure.ActiveDirectory.GraphClient相比,调用Microsoft.Graph时用户的数据内容不足的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的代码从Microsoft.Azure.ActiveDirectory.GraphClient更改为同一注册应用程序上的Microsoft.Graph.在某些数据结构(例如,Group,Company)上,提取的数据是相同的.但是用户的提取数据不同. (我正在使用Graph API的V1.0.)

I want to change my code from Microsoft.Azure.ActiveDirectory.GraphClient to Microsoft.Graph on the same registered App. On some data structure(e.g. Group, Company), the fetched data are the same. but the fetched data of User are different. (I am using the V1.0 of the Graph API.)

例如,当我尝试通过upn来获取某个用户时. 旧方法是调用:

For example, when I try to fetch certain user by its upn. The old method is to call:

graphClient.Users.Where(user => user.UserPrincipalName.Equals(upn)).ExecuteSingleAsync() //graphClient is an instance of ActiveDirectoryClient

graphClient.Users.Where(user => user.UserPrincipalName.Equals(upn)).ExecuteSingleAsync() //graphClient is an instance of ActiveDirectoryClient

新呼叫是:

graphClient.Users.Request().Filter("userPrincipalName eq '"+ upn + "'").GetAsync() //graphClient is an instance of GraphServiceClient

graphClient.Users.Request().Filter("userPrincipalName eq '"+ upn + "'").GetAsync() //graphClient is an instance of GraphServiceClient

尽管它们都将使用输入UPN的正确信息来获取同一用户.但是与旧方法相比,新方法获取的数据还不够,其许多属性都是空的.例如AccountEnabled,Othermails,AssignedPlans和UserType.

Although they will both fetch the same user with correct information of input UPN. But compared to the old method, data fetched by new method are not sufficient, many of its properties are null. Such as AccountEnabled, Othermails, AssignedPlans, and UserType.

我是否以错误的方式调用GraphServiceClient,以致于它无法获取所有数据?还是应该通过补充调用获取这些null属性?

Am I calling GraphServiceClient in a wrong way so that it cannot fetch all the data? Or should I fetch these null properties with a supplement call?

谢谢!

推荐答案

我是否以错误的方式调用GraphServiceClient,以致于它无法获取所有数据?

Am I calling GraphServiceClient in a wrong way so that it cannot fetch all the data?

这是Microsoft Graph用户API的正常行为,请参阅Microsoft Graph用户API

That's the normal behaviour of Microsoft Graph user API, see Microsoft Graph user API here and this extract:

默认情况下,仅返回有限的一组属性(businessPhones, displayName, givenName, id, jobTitle, mail, mobilePhone, officeLocation, preferredLanguage, surname, userPrincipalName).本示例说明了默认的请求和响应.

By default, only a limited set of properties are returned ( businessPhones, displayName, givenName, id, jobTitle, mail, mobilePhone, officeLocation, preferredLanguage, surname, userPrincipalName ). This example illustrates the default request and response.


还是应该通过补充调用获取这些null属性?

Or should I fetch these null properties with a supplement call?

我们可以使用$ select参数来查询属性.以下是您可以参考的演示代码.您可以选择所需的属性.这个对我有用.

We could use $select parameter to query the property. The following is demo code you could refer to. You could select the properties that you wanted. It works for me.

var user = graphserviceClient.Users.Request().Select(x =>new 
        {
            x.UserPrincipalName,
            x.DisplayName,
            x.AccountEnabled,
            x.UsageLocation

        } ).Filter("userPrincipalName eq '" + upn + "'")
       .GetAsync().Result;

测试结果:

这篇关于与Microsoft.Azure.ActiveDirectory.GraphClient相比,调用Microsoft.Graph时用户的数据内容不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆