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

Our company is on Office 365. So when users sign in to my mvc website, I'd like to display their photo, like Outlook does.
Where does outlook get the user's photo? 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. Thus Outlook must be getting it elsewhere. Where and how?
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.

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?
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.
The user photo is available in your ADAzure, because your users most likely are applying their photos in Outlook (or online).
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.
How to get user's exchange/outlook/office365 photo?
There are quite a few ways to get the photo from Azure AD:
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 Services (EWS Managed API and/or REST API): Basically using the AutoDiscover service to the URL 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: Basically sending a GET request to the Outlook API (with the bearer access token) at the URL{version}/me/photo for your own, and at the URL{version}/users/ 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 Unified API (aka Graph): Basically nearly the same as the older API. Send a GET request (with bearer token) to the URL{version}/me/photo/ for your own photo and{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)
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


Microsoft.Graph photo retrieve function

Has anyone been able to get this line to work?
I get a timeout. Also didn't work as a REST Get.
Could it be a bug in the library?
This operation in version 1.0 supports only a user's work or school mailboxes and not personal mailboxes.
Please ensure that you were calling this REST using the work or school account and the user have the subscription like Office 365 that making the user own the mailbox.
After meeting above two requirements, this REST works well for me.
And if the user didn't have the mailbox, you can get the thumbnail photo for a specified user from the thumbnailPhoto property via Azure AD Graph. Here is the request for your reference:

Outlook REST API - How to retrieve a User Photo

I would like to get the photos of my users from outlook and store them in my database. I want it to be done automatically by the programm with no user interaction required, because i know their email and password.
I´m trying to use this guide:
I have already registered my website (.NET MVC 5), but I don´t know how to do the authentication and access token part, because half of the links of the guide don´t work and i can´t find any helpful tutorial / code snippets somewhere else.
I´m deeply grateful for any help.
Instead of using Office 365 REST API, we can use the Microsoft Graph.
And since you don't want to the user participate in the authentication, you can using the Client Credentials Grant Flow which permits a web service (a confidential client) to use its own credentials to authenticate when calling another web service, instead of impersonating a user.
Here is the REST API to get the photo for a specific user for your reference:
The app requires one of the following scopes to request the photo of user:
User.Read; User.ReadBasic.All; User.Read.All; User.ReadWrite.All; User.Read
And refer to here to register the app using the Microsoft Graph API.

Access multiple Office 365 Outlook calendars within organization in UWP using OAuth2.0?

My organization currently uses Office365, and I am creating a Universal Windows Platform app that essentially needs to access the calendars of multiple accounts within the organization. I am currently using the Office365 Rest API, and already can successfully query a single account's calendar data, after getting an OAuth2.0 access token for a particular user.
After searching through multiple resources and existing Stackoverflow questions, I have tried the following with no luck to get multiple user account calendars without having to sign in to each account individually:
Performing a GET request with the graph API from Microsoft Graph API
Performing a GET request using navigation paths to users calendars using this method and other variations. (Returns 403 access denied error)
I also found a possible solution by using EWS Managed API, but I was unsure of its compatibility with UWP and our current Office 365 setup.
Lastly, I looked into building daemon or service apps, but this method seemed really unnecessary and possibly impossible with the current configuration of Azure. It requires asymmetric key crypt. set up within the system, and re-configuring the app as a whole within Azure.
Any help is appreciated.
[EDIT]: FYI all of the calendars have been made public, and can be viewed in the web client of Outlook.
I found to what I think is the only solution with today's version of UWP and the Office365 REST Api.
First I started up a different application that was compatible with the EWS Managed API and made a query to the Microsoft Exchange server that my organization is using. I tracked this request using Fiddler, the http debugger, to view the actual request and response. This way, I could find the exact endpoint of my exchange server.
Then, I navigated to the exchange service's URL in my browser, and saved the service's WSDL file, and imported it as a service reference to my UWP solution.
Finally, I set up a Httpclient, and generated a request to match all of the properties of the request made from the successful EWS Managed API call that I tracked in Fiddler.

How to get metadata of an unshared file from another user with google drive api?

I'm currently working on a C# mvc web app using the Google Reports API from Admin SDK to receive notifications when something happens on my Google Drive.
Then, I need to use in addition the Drive REST API GET Request to build the file Path (and more) by using the the doc_id given by the Reports API.
Everything is working fine, except when the Report API notifies me with another user unshared file. The Drive REST API is trying to find the file with no success.
Here is the Error 404 returned:
File not found: 0B48ytfDI5h8qY2k4VzdjMkZRNXM [404]
Errors [
Message[File not found: 0B48ytfDI5h8qY2k4VzdjMkZRNXM] Location[file - other] Reason[notFound] Domain[global]
I'm using this scope : DriveService.Scope.Drive
The file owner is able to see metadata of his file by using this form, and I still have the Error 404.
I'm the drive administrator and on my Google Apps Admin Settings, I've tried different configs with no success, even with the Default Shared Link on Everyone from the domain.
So my question is: Is that possible to get file meta data when you are not the file owner and the file isn't shared ?
PS: I'm using a Google Apps for work unlimited in relation with my work domain, so I thought I could at least get metadata files as an admin even if the file is not shared.
To my knowledge, the only way to access the user's file in Drive API is through setting up a Service Account for your web application. You can read more about this in the Drive API documentation under Domain-Wide Delegation.
To give a brief summary:
Service Account is an account that belongs to your application instead of to an individual end user. This allows your application to have authority to make API calls as users in your domain (also to "impersonate" users).
To get started, the following tasks have to be performed:
Create or select a project in the Google Developers console and enable the API (e.g. Drive API).
Go to Credentials, add new credentials and select Service Account. More details here.
This will create three items (client ID, private key file, and email address), which is required in authorizing your application in the Google Apps domain's Admin Console.
Now, the service account that you have created needs to be granted access to the Google Apps domain's user data that you want access. This will require the administrator to authorize the service account in the Admin console. Since it's already provided in the documentation, you can access the appropriate steps in the document.
Now, your application can instantiate an authorized Drive service Object (i.e. metadata) on behalf of your Google Apps domain's users. Hope this helps and Good luck!

retrieve details of users from the exchange server

I am using exchange server 2007 (outlook) to configure email accounts..
How can we retrieve the details of the users (mailboxes) present on the exchange server.
This feature is there in outlook. By double clicking the id and checking details.
But, how can this be done programmatically? (using c#)
You can use either the Web Services part of the Exchange SDK or the newer Web Services Managed API to gather info or do just about anything Outlook can do (see this chart for the differences). Both links given should lead you to how-to's, reference pages, and example code to help you get started.
If you want to query the Global Address List (GAL), there are several methods. In OWA (thus, HTTP protocol) there's a command called "galfind" (example code here; reference here). Or you can use ADSI to search the GAL. Or there's CDO or MAPI, but I would steer away from those if possible.