Not able to get photo using Microsoft graph API

2020-04-18 09:12发布

问题:

We are integrating Microsoft Azure AD with our application. I am trying to get user profile pic using Microsoft Graph API (https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}/photo/$value) . But its not working for me. I have given all permission required for this API in application but every time getting below response. Can you please let me what configuration I missed.

Response:

{

    "error": {

        "code": "ResourceNotFound",

        "message": "Resource could not be discovered.",

        "innerError": {

            "request-id": "dc27c602-5734-4dec-9b2a-8b42d5577073",

            "date": "2019-07-02T10:33:42"

        }

    }

}

Thanks

回答1:

Reading and updating a user's profile photo is only possible if the user has a mailbox. Additionally, any photos that may have been previously stored using the thumbnailPhoto property (using the Office 365 unified API preview, or the Azure AD Graph, or through AD Connect synchronization) are no longer accessible through the Microsoft Graph photo property of the user resource. For more details You could check official docs here

Microsoft Graph v1.0 retrieves the user's profilePhoto from Exchange Online, not Azure Active Directory. As such, users that don't have a mailbox provisioned in Exchange Online will not have a profilePhoto available

Your Case:

You could try with Microsoft Graph REST API Beta version request URL in flowing format:

https://graph.microsoft.com/beta/users/UserIdOrPrincipalName/photo/$value

See the screen shot below:

Azure Active Directory Profile Picture:

Post Man Request Example:

Request URL:

https://graph.microsoft.com/beta/users/UserIdOrPrincipalName/photo/$value

Points To Remember:

Make sure you have upload user photo in azure portal profile.

Note:

APIs under the /beta version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported