How to fetch user profile image from Azure Active Directory from SharePoint Online page?
-
21-12-2020 - |
Question
I have to display all SharePoint Online user's profile information including profile picture on a page in SharePoint Online.
Here some of user has profile picture set in Office 365, while some users have profile picture added in Azure Active Directory.
I am able to use REST API call but it gives me the profile picture of Office 365 users. But I want to pull profile image for SharePoint Online user from Azure Active Directory.
How I can achieve this?
One way is using Graph API by Microsoft, But its usage is confusing me. If any one have used Microsoft Graph API to fetch user's profile image from delve then please share some snippets.
Solution
In Graph API, you can use the below endpoint to fetch photo from Azure AD:
https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}/photo/$value
So, for example, you have user's email address as alans@CIE493742.onmicrosoft.com
, then your url will be:
https://graph.microsoft.com/v1.0/users/alans@CIE493742.onmicrosoft.com/photo/$value
To get this, you need to set the app permission as
Profile photo of any user in the tenant including the signed-in user - User.ReadBasic.All; User.Read.All; User.ReadWrite.All
To test your endpoints, sign in to graph explorer and check