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:

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();

Leave a Reply