【问题标题】:City and Country from Microsoft Graph equals nullMicrosoft Graph 中的城市和国家/地区等于 null
【发布时间】:2017-09-25 16:00:39
【问题描述】:

我正在使用 microsoft graph 从活动目录中获取用户数据。当我使用 sdk 时,我只获得了有关用户的基本信息,例如。 “displayName”、“mail”、“userPrincipalName”、“id”。其他一切都有空值。我在 azure 中的应用程序有权查看信息。当我打开 azure 的所有权限时,结果是一样的。如何获取城市和国家/地区信息?

【问题讨论】:

标签: c# azure


【解决方案1】:

这是预期行为,因为 Microsoft Graph API 端点为User 资源返回一组默认属性。

要返回其他属性,需要通过$select query option 明确请求它们。在msgraph-sdk-dotnet 的情况下,可以像这样指定其他属性:

var users = await graphClient.Users.Request().Select("companyName,city,country,contacts,contactFolders").GetAsync();

另一种选择是定位Microsoft Graph beta endpoint。对于端点https://graph.microsoft.com/beta/users,连同默认属性,至少companyName,city,country 将包含在结果中。

下面的 sn-p 显示了如何将msgraph-sdk-dotnet 初始化为目标 API beta 版本:

_graphClient = new GraphServiceClient("https://graph.microsoft.com/beta",
            new DelegateAuthenticationProvider(async (requestMessage) =>
                {
                    // Passing tenant ID to the sample auth provider to use as a cache key
                    string accessToken = await _authProvider.GetUserAccessTokenAsync(userId);

                    // Append the access token to the request
                    requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                })); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-28
    • 2011-10-12
    • 2015-11-18
    • 1970-01-01
    • 2012-03-29
    • 1970-01-01
    • 1970-01-01
    • 2017-09-02
    相关资源
    最近更新 更多