1

I am trying to get an image of a user with the help of MS Graph.

However, a response is always undefined and there is no error given but If I run a query on MS Graph Explorer I get the full image of a user. My query looks like /users/[email protected]/photo/$value.

 this.props.context.msGraphClientFactory.getClient().then(async(client:MSGraphClient): Promise<void> => {
         client.api('/users/'+ this.props.people[i].email+ '/photo/$value').get(async(error, response, rawResponse?: any) => {
            console.log(response);
            let picture = btoa(response);
            .... etc
            ...
          });
      });

1 Answer 1

1

You need to use id or userPrincipalName of a user to get the user photo. like:

/users/{id | userPrincipalName}/photo/$value.

You can check full documentation at: Get the photo.

Additional documentation

Consume the Microsoft Graph in the SharePoint Framework

1
  • Yes, I know that you need to use userPrincipalName or id. My principal name is the same as email, so I am assuming I should get a response that is not undefined since the exact same query works on MS Graph Explorer?
    – AnB
    Jun 11, 2020 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.