Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Graph Client with Client Credentials Flow No Photo data

I’m using the client credentials flow to get users – I’m specifically seeking their photo.

I seem to be able to retrieve all the textual data but Photo is always null. In Azure Portal > Azure AD I can see a picture next to each user so it must be somewhere.

eg:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

IGraphServiceUsersCollectionPage users = await graphServiceClient.Users
    .Request()
    .Filter("startswith(mail,'neil@email.com')")        
    .GetAsync();

users[0] has Id, DisplayName etc.. but no Photo

Where am I going wrong? (All the examples seem to be for /Me/ but this is not my scenario)

>Solution :

You cannot get photo of all users by calling /users endpoint. You need to make a separate call for each user to get photo

To get metadata about photo

GET /users/{user_id}/photo

To get content

GET /users/{user_id}/photo/$value

Code

// metadata
var profilePhoto = await graphClient.Users["{user_id}"].Photo
    .Request()
    .GetAsync();

// content
var stream = await graphServiceClient.Users["{user_id}"].Photo.Content
    .Request()
    .GetAsync();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading