我希望能够在Azure Active directory中获得所有用户的office365照片。
现在,我可以使用图形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;
}
但我不确定如何将来自https://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/profilephoto_get的the getting photos part集成到代码中。
感谢任何帮助或代码示例!
发布于 2019-07-09 16:30:25
这有助于获取图像
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 = "";
}
发布于 2017-02-09 17:03:31
您可以使用graphClient.Me.Photo.Content
获取照片,它将在流中检索照片的二进制数据:
public async Task GetPictureAsync()
{
GraphServiceClient graphClient = GetGraphServiceClient();
var photo = await graphClient.Me.Photo.Content.Request().GetAsync();
using (var fileStream = File.Create("C:\\temp\\photo.jpg"))
{
photo.Seek(0, SeekOrigin.Begin);
photo.CopyTo(fileStream);
}
}
发布于 2021-10-26 20:15:30
在2021年,你可以这样做:
Stream photo = await graphServiceClient.Me.Photo.Content.Request().GetAsync();
ViewData["Photo"] = Convert.ToBase64String((photo as MemoryStream).ToArray());
然后在你的html中:
<img src="data:image/png;base64, @ViewData["Photo"]" />
https://stackoverflow.com/questions/42126660
复制相似问题