c# 如何使用 Microsoft Graph API 获取 Office 365 用户照片

标签 c# microsoft-graph-api office365api outlook-restapi office365-restapi

我希望能够在 Azure 事件目录中获取所有用户的 office365 照片。

现在我可以使用 graph SDK 获取当前用户的电子邮件

GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();

public async Task<string> GetMyEmailAddress(GraphServiceClient graphClient)
    {          
        User me = await graphClient.Me.Request().Select("mail,userPrincipalName").GetAsync();
        return me.Mail ?? me.UserPrincipalName;
    }

但我不确定如何集成 the getting photos part来自 https://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/profilephoto_get进入代码。

感谢任何帮助或代码示例!!

最佳答案

这有助于获取图像

 GraphServiceClient graphServiceClient = GetAuthenticatedGraphServiceClient();

 Stream photo = await graphServiceClient.Me.Photo.Content.Request().GetAsync();

 if (photo != null)
 {
     MemoryStream ms = new MemoryStream();
     photo.CopyTo(ms);
     byte[] buffer = ms.ToArray();
     string result = Convert.ToBase64String(buffer);
     string imgDataURL = string.Format("data:image/png;base64,{0}", result);
     ViewBag.ImageData = imgDataURL;
 }
 else
 {
      ViewBag.ImageData = "";
 }

enter image description here

关于c# 如何使用 Microsoft Graph API 获取 Office 365 用户照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42126660/

相关文章:

javascript - Microsoft Graph - 无效的筛选子句

microsoft-graph-api - 为什么每当我的 MS Graph API 邮件搜索没有找到结果时,我就会收到网关超时?

azure - Office365 OAuth API 返回错误 "AADSTS90093: Does not have access to consent"

c# - 在 EF 中保存对象时,不会在数据库中建立新的多对多连接

microsoft-graph-api - 微软图形 API : 403 Forbidden error when trying to retrieve policies on tenant

javascript - AADSTS50011 : The reply URL specified in the request does not match the reply URLs configured for the application:

office365 - 加载项命令功能区在 Excel Online 中显示,但在 Excel for Windows 中不显示

c# - 在 Linq to Sql 中使用排序规则

c# - C++ -> C# 使用 SWIG : how to use default constructor for a class

c# - 使用 C# 将数据插入 SQLite 数据库