Mii*_* L. 12 c# asp.net-mvc gravatar office365
我们有一个系统将以某种方式与Office 365集成,我们希望使用Office 365系统中用户设置的配置文件图片,而不是自己存储此图像/引用.但是,我找不到任何方法从Office 365外部访问此图像(例如通过电子邮件地址).
换句话说,Office 365是否能够以与Gravatar类似的方式提供用户的个人资料图片?
小智 6
您还可以使用Office365 Unified 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;
Run Code Online (Sandbox Code Playgroud)
小智 1
您可以使用Graph API获取用户实体记录,其中包含个人资料图片
http://msdn.microsoft.com/en-us/library/hh974483.aspx - 请参阅thumbnailPhoto 字段。
有关 REST API 信息:http://msdn.microsoft.com/en-us/library/hh974478.aspx