No Sufficient Data Content of User When Calling Microsoft.Graph Compared to Microsoft.Azure.ActiveDirectory.GraphClient

白昼怎懂夜的黑 提交于 2019-12-24 11:00:09

问题


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.)

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

And the new one is to call:

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

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.

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?

Thanks!


回答1:


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

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

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.


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

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;

Test result:



来源:https://stackoverflow.com/questions/51830384/no-sufficient-data-content-of-user-when-calling-microsoft-graph-compared-to-micr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!