如何获取用户的交流/外景/office365照片? [英] How to get user's exchange/outlook/office365 photo?

查看:98
本文介绍了如何获取用户的交流/外景/office365照片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的公司位于Office 365上.因此,当用户登录我的asp.net mvc网站时,我希望像Outlook一样显示他们的照片.

Our company is on Office 365. So when users sign in to my asp.net mvc website, I'd like to display their photo, like Outlook does.

Outlook在哪里获取用户的照片?以及如何以编程方式实现它?

Where does outlook get the user's photo? And how I can get to it programmatically?

我尝试查找ActiveDirectory并获取thumbnailPhoto,但是对于大多数用户而言,它是空白的.因此,Outlook必须将其转移到其他地方.在哪里以及如何?

I've tried hitting up the ActiveDirectory and fetching the thumbnailPhoto, but it's blank for most users. Thus Outlook must be getting it elsewhere. Where and how?

我还看到了一些使用Microsoft.Office.Interop.Outlook程序集的示例(假设它需要安装Outlook才能起作用).但是,此网站在未安装Outlook的服务器上运行.

I've also seen some examples where Microsoft.Office.Interop.Outlook assembly is used (assuming it requires Outlook installed to function). However, this website runs on a server that doesn't have Outlook installed.

推荐答案

我尝试查找ActiveDirectory并获取 thumbnailPhoto,但对于大多数用户而言为空白.因此,Outlook必须是 将其转移到其他地方.在哪里以及如何?

I've tried hitting up the ActiveDirectory and fetching the thumbnailPhoto, but it's blank for most users. Thus Outlook must be getting it elsewhere. Where and how?

用户照片 在您的AD 本地中不可用,因为您的用户很可能首先没有将其存储在该位置,除非您提供了它们通过将其写入AD的应用.

The user photo is not available in your ADon-premise, because your users most likely haven't stored it there in the first place unless you have provided them with an app which writes it to the AD.

在AD Azure 中可以使用用户照片 ,因为您的用户很可能在Outlook(或在线)中应用了他们的照片.

The user photo is available in your ADAzure, because your users most likely are applying their photos in Outlook (or online).

我假设您的本地AD已通过 Dirsync ADConnect 实用程序与Azure AD进行了同步.如果是,则实际上photothumbnailphoto属性仅单向同步(从内部部署到Azure),并且不会回写.参考

I am assuming that your on-premise AD is being synced with Azure AD via Dirsync or ADConnect utilities. If yes, then actually the photo or thumbnailphoto attributes are synced only one-way (from on-premise to Azure) and are not written back. Reference here for DirSync and here for ADConnect.

这就是为什么您无法从广告中获取它的原因.

This is why you are not able to get it out of your AD.

如何获取用户的交流/外景/office365照片?

How to get user's exchange/outlook/office365 photo?

有很多方法可以从Azure AD获取照片:

There are quite a few ways to get the photo from Azure AD:

  1. Exchange Web服务(EWS):通过使用 PictureData 元素

  1. Exchange Web Services (EWS): by using the GetUserPhoto operation. Basically sending a SOAP envelope with the email address and size. the XML response will get you the base64-encoded photo contained in the PictureData element

Exchange Web服务(EWS托管API和/或REST API):基本上使用自动发现服务访问URL https://outlook.office365.com/ews/exchange.asmx,然后通过Microsoft.Exchange.WebServices.Data上的EWS.Service.ConnectToService方法进行连接>需要为其引用库的名称空间(一个DLL,您可以从此处下载 ).方法保持不变GetUserPhoto,并且图像以二进制形式包含在响应中.

Exchange Web Services (EWS Managed API and/or REST API): Basically using the AutoDiscover service to the URL https://outlook.office365.com/ews/exchange.asmx and then connect via EWS.Service.ConnectToService method on the Microsoft.Exchange.WebServices.Data namespace for which you need a reference to the library (a DLL that you can download from here). The method remains the same GetUserPhoto and the image is contained in the response in binary.

Outlook REST API::基本上,您将URL https://outlook.office.com/api/{version}/me/photo上的GET请求发送到Outlook API(带有承载访问令牌的 )自己的,网址为https://outlook.office.com/api/{version}/users/email@example.com/photo.您将获得二进制格式的照片流作为响应.不要忘了附加$value以获得blob,否则您将获得元数据. 此处引用了更多详细信息.

Outlook REST API: Basically sending a GET request to the Outlook API (with the bearer access token) at the URL https://outlook.office.com/api/{version}/me/photo for your own, and at the URL https://outlook.office.com/api/{version}/users/email@example.com/photo. You get the photo stream in binary format as the response. Don't forget to append $value to get the blob otherwise you'll get the metadata. More details referenced here.

Office 365统一API(又名Graph):基本上与旧版API几乎相同.向您的照片向URL https://graph.microsoft.com/{version}/me/photo/发送GET请求(带有承载令牌),为其他用户发送https://graph.microsoft.com/{version}/users/UPN/photo请求.或多或少相同. 此处引用了更多详细信息.还有此处的沙箱,供您浏览示例和API参考.您也可以自己尝试一下在此处进行交互式在线(在启动您的帐户之前,请不要忘记登录获取请求)

Office 365 Unified API (aka Graph): Basically nearly the same as the older API. Send a GET request (with bearer token) to the URL https://graph.microsoft.com/{version}/me/photo/ for your own photo and https://graph.microsoft.com/{version}/users/UPN/photo for another user. More or less the same. More details referenced here. There is also a sandbox here for you to explore the samples and API references. You can also try it out yourself online interactively here (Don't forget to sign-in before firing your get requests)

希望有帮助.

更多参考资料:此处 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆