繁体   English   中英

如何使用 Microsoft.Graph SDK 或 User.Identity 获取个人资料图片

[英]How to get profile picture with Microsoft.Graph SDK or User.Identity

我已经使用 Microsoft Azure 中的快速入门项目成功实现了身份验证,但现在我无法获取登录用户的个人资料图片。

我曾尝试使用 Microsoft.Graph SDK,但Photo不断收到null

                IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
                    .Create(ClientId)
                    .WithTenantId(TenantId)
                    .WithClientSecret(ClientSecret)
                    .Build();

                AuthorizationCodeProvider authProvider = new AuthorizationCodeProvider(confidentialClientApplication);

                // Create an authentication provider.
                ClientCredentialProvider authenticationProvider = new ClientCredentialProvider(confidentialClientApplication);
                // Configure GraphServiceClient with provider.
                GraphServiceClient graphServiceClient = new GraphServiceClient(authenticationProvider);
                var users = await graphServiceClient.Users.Request().GetAsync();

我还尝试使用 id 和.Select("Photo")获取特定用户,但结果是相同的

var temp = await graphServiceClient.Users[user_id]
                    .Request()
                    .Select("Photo")
                    .GetAsync();

也许我的实现是错误的,任何帮助或建议将不胜感激。

要获得一张 stream 的照片,您可以使用此代码

using (var photoStream = await graphServiceClient.Users[user_id].Photo.Content
                               .Request()
                               .GetAsync())
{
    // your code       
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM