首页 > 解决方案 > 无法更新 Azure 门户上的 B2C 本地用户个人资料照片/使用带有应用程序颁发令牌的 Graph

问题描述

我有 B2C 本地帐户,当我尝试使用带有应用程序颁发令牌的 Graph API 获取/更新他们的个人资料信息时,它起作用了。但是当我尝试获取/更新他们的个人资料照片时,我收到 404 错误。

请求:(获取)

https://graph.microsoft.com/v1.0/users/{userOid}/photo

回复:404

{
  "error": {
    "code": "ImageNotFound",

    "message": "Exception of type 'Microsoft.Fast.Profile.Core.Exception.ImageNotFoundException' was thrown.",

    "innerError": {
      "date": "2021-10-26T16:12:52",

      "request-id": "ac24acee-8317-4d77-95ea-c69df189e7cb",

      "client-request-id": "ac24acee-8317-4d77-95ea-c69df189e7cb"
    }
  }
}

request: (PUT/POST) 并设置内容类型

https://graph.microsoft.com/v1.0/users/{userOid}/photo/$value

回复:404

{
  "error": {
    "code": "UnknownError",

    "message": "{\r\n \"errorCode\": \"ErrorUserResolutionFailedUserDoesNotExist\",\r\n \"message\": \"Exception of type 'Microsoft.Fast.Profile.Core.Exception.ProfileNotFoundException' was thrown.\",\r\n \"target\": null,\r\n \"details\": null,\r\n \"innerError\": null,\r\n \"instanceAnnotations\": []\r\n}",

    "innerError": {
      "date": "2021-10-26T16:13:55",

      "request-id": "3517b374-a08d-41a1-8f68-9c9da3cbfb3b",

      "client-request-id": "3517b374-a08d-41a1-8f68-9c9da3cbfb3b"
    }
  }
}

标签: azure-active-directorymicrosoft-graph-apiazure-ad-b2cazure-ad-graph-api

解决方案


目前,您正在使用 Microsoft Graph REST API V1.0 来获取/更新 B2C 本地帐户的用户照片。

但是1.0版本的这些操作只支持用户的工作或学校邮箱,不支持个人邮箱

因此,您可以使用 Microsoft Graph REST API 测试版来获取/更新 B2C 本地帐户的用户照片。

使用 beta 版本获取/更新用户照片时,此操作首先尝试获取/更新 Microsoft 365 中的照片。如果失败(由于用户没有邮箱),此 API 将尝试获取/更新 Microsoft 365 中的照片Azure 活动目录

注意:要为用户更新个人资料照片,请仅使用 PUT 操作。

要获取用户的头像,请确保用户在 Azure AD 中有头像。否则,它会抛出ImageNotFound错误。

参考

profilePhoto 资源类型- Microsoft Graph beta | 微软文档

profilePhoto 资源类型- Microsoft Graph v1.0 | 微软文档


推荐阅读