c# - Office 365个人资料头像图片

标签 c# asp.net-mvc office365 gravatar

我们有一个系统将在某些方面与 Office 365 集成,我们希望在 Office 365 系统中使用用户设置的个人资料图片,而不是我们自己存储此图像/引用。但是,我找不到从 Office 365 外部访问此图像的任何方法(例如通过电子邮件地址)。

换句话说,Office 365 是否能够以类似于 Gravatar 的方式提供用户的个人资料图片? ?

最佳答案

您还可以使用 Office365 统一 API(预览版)https://msdn.microsoft.com/office/office365/APi/photo-rest-operations

并用作 Base64 编码图像。请注意自上次更新以来更改的 API。

这是我的代码:

 HttpClient client = new HttpClient();
 HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get,
       "https://outlook.office.com/api/beta/me/photos('96x96')/$value");
        request.Headers.Add("ACCEPT", "image/*");
        request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authResult.AccessToken);
        HttpResponseMessage response = await client.SendAsync(request);
        byte[] byteArray = await response.Content.ReadAsByteArrayAsync();

        string base64ImageRepresentation = Convert.ToBase64String(byteArray);

        if (!response.IsSuccessStatusCode && response.StatusCode >= HttpStatusCode.BadRequest)
        {
            return string.Empty;
        }

        return base64ImageRepresentation;

关于c# - Office 365个人资料头像图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12477513/

相关文章:

c# - 将C#中的长字符串发送到Python的最快方法

asp.net-mvc - 如何准确知道哪个字段引发了 DbUpdateException

ajax获取对Office365 REST Api的请求失败CORS?

c# - 遍历 MySQL 表

c# - 这个指针算术真的是线程安全的吗?

c# - 处理器架构与 SQLite Nuget 包和任何 CPU Web 项目不匹配

c# - 单个 MVC 页面上的多个表单

c# - 如何将 ENUM 值转换为 String 从 View 到 Controller

添加数据透视表时 Excel 查询出现重复

office365 - 微软office 365组: Guest user are unable to do drive call using graph endpoint