[英]How to get user's exchange/outlook/office365 photo?
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. 我们公司在Office 365上。所以当用户登录我的asp.net mvc网站时,我想显示他们的照片,就像Outlook一样。
Where does outlook get the user's photo? outlook在哪里获取用户的照片? And how I can get to it programmatically?
以及如何以编程方式实现它?
I've tried hitting up the ActiveDirectory and fetching the thumbnailPhoto, but it's blank for most users. 我试过点击ActiveDirectory并获取thumbnailPhoto,但对于大多数用户来说这是空白的。 Thus Outlook must be getting it elsewhere.
因此,Outlook必须将其纳入其他地方。 Where and how?
在哪里以及如何?
I've also seen some examples where Microsoft.Office.Interop.Outlook assembly is used (assuming it requires Outlook installed to function). 我还看到了一些使用Microsoft.Office.Interop.Outlook程序集的示例(假设它需要安装Outlook才能运行)。 However, this website runs on a server that doesn't have Outlook installed.
但是,此网站在未安装Outlook的服务器上运行。
I've tried hitting up the ActiveDirectory and fetching the thumbnailPhoto, but it's blank for most users.
我试过点击ActiveDirectory并获取thumbnailPhoto,但对于大多数用户来说这是空白的。 Thus Outlook must be getting it elsewhere.
因此,Outlook必须将其纳入其他地方。 Where and how?
在哪里以及如何?
The user photo is not available in your AD on-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 内部部署中 不可用,因为您的用户很可能首先没有将其存储在那里,除非您为他们提供了将其写入AD的应用程序。
The user photo is available in your AD Azure , because your users most likely are applying their photos in Outlook (or online). 用户照片是在你的AD Azure中可用的,因为你的用户最有可能在Outlook(或在线)将他们的照片。
I am assuming that your on-premise AD is being synced with Azure AD via Dirsync or ADConnect utilities. 我假设您的内部部署AD正在通过Dirsync或ADConnect实用程序与Azure AD 同步 。 If yes, then actually the
photo
or thumbnailphoto
attributes are synced only one-way (from on-premise to Azure) and are not written back. 如果是,那么实际上
photo
或thumbnailphoto
属性仅以单向同步(从内部部署到Azure)并且不会被回写。 Reference here for DirSync and here for ADConnect . 这里参考DirSync和ADConnect 。
This is why you are not able to get it out of your AD. 这就是为什么你无法将它从你的AD中拿出来的原因。
How to get user's exchange/outlook/office365 photo?
如何获得用户的交换/ outlook / office365照片?
There are quite a few ways to get the photo from Azure AD: 从Azure AD获取照片的方法有很多种:
Exchange Web Services (EWS): by using the GetUserPhoto operation. Exchange Web服务(EWS):使用GetUserPhoto操作。 Basically sending a SOAP envelope with the email address and size.
基本上发送带有电子邮件地址和大小的SOAP信封。 the XML response will get you the base64-encoded photo contained in the PictureData element
XML响应将为您提供PictureData元素中包含的base64编码的照片
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 ). Exchange Web服务(EWS托管API和/或REST API):基本上使用自动发现服务访问URL
https://outlook.office365.com/ews/exchange.asmx
,然后通过Microsoft.Exchange.WebServices.Data
上的EWS.Service.ConnectToService
方法进行连接需要引用库的Microsoft.Exchange.WebServices.Data
命名空间( 可以从此处下载的DLL )。 The method remains the same GetUserPhoto
and the image is contained in the response in binary. 该方法保持相同的
GetUserPhoto
,图像包含在二进制响应中。
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
. Outlook REST API:基本上向您自己的URL
https://outlook.office.com/api/{version}/me/photo
发送GET
请求到Outlook API( 带有承载访问令牌 ),以及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. 不要忘记附加
$value
来获取blob,否则你将获得元数据。 More details referenced here. 这里引用了更多细节。
Office 365 Unified API (aka Graph): Basically nearly the same as the older API. Office 365 Unified API(又名图形):基本上与旧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. 发送
GET
请求(带有持票人令牌)到URL https://graph.microsoft.com/{version}/me/photo/
为您自己的照片和https://graph.microsoft.com/{version}/users/UPN/photo
为另一个用户。 More or less the same. 或多或少相同。 More details referenced here .
这里引用了更多细节 。 There is also a sandbox here for you to explore the samples and API references.
这里还有一个沙箱供您探索示例和API参考。 You can also try it out yourself online interactively here ( Don't forget to sign-in before firing your get requests )
您也可以在这里 以 交互方式在线尝试(请不要忘记在解除获取请求之前登录 )
Hope that helps. 希望有所帮助。
Some more references: here , here and here . 更多参考资料: 这里 , 这里和这里 。
Try this method,It works for me It will fetch the user profile picture from account 尝试这种方法,它适用于我它将从帐户中获取用户个人资料图片
https://outlook.office365.com/owa/service.svc/s/GetPersonaPhoto?email=plambhure@sanjeevgroup.com&UA=0&size=HR64x64&sc=1468233338850 https://outlook.office365.com/owa/service.svc/s/GetPersonaPhoto?email=plambhure@sanjeevgroup.com&UA=0&size=HR64x64&sc=1468233338850
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.