更新 profilephotoUpdate profilephoto

命名空间:microsoft.graphNamespace: microsoft.graph

更新登录 用户、指定联系人的照片。由于目前每个 REST 请求的总大小限制为 4 MB,这就要求可添加的照片小于 4 MB。Update the photo for the signed-in user, or the specified group or contact. Since there is currently a limit of 4MB on the total size of each REST request, this limits the size of the photo you can add to under 4MB.

可以在版本 1.0 中使用 PATCH 或 PUT 执行此操作。You can use either PATCH or PUT for this operation in version 1.0.

注意:1.0 版本中的操作仅支持用户的工作或学校邮箱,不支持个人邮箱。Note This operation in version 1.0 supports only a user's work or school mailboxes and not personal mailboxes.

权限Permissions

要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions.

  • 已登录用户的个人资料照片 - User.ReadWrite、User.ReadWrite.AllProfile photo of the signed-in user - User.ReadWrite, User.ReadWrite.All
  • 的个人资料照片 - Group.ReadWrite.AllProfile photo of a group - Group.ReadWrite.All
  • 联系人的照片 - Contacts.ReadWritePhoto of a contact - Contacts.ReadWrite

注意 若要更新组织中任何用户的照片,应用必须具有 User.ReadWrite.All 应用程序权限,并以其自己的身份而不是代表用户来调用此 API。Note To update the photo of any user in the organization, your app must have the User.ReadWrite.All application permission and call this API under its own identity, not on behalf of a user. 若要了解详细信息,请参阅在没有已登录用户的情况下进行访问To learn more, see get access without a signed-in user.

注意: 当前有一个已知问题,即使用应用程序权限访问组照片。Note: There is currently a known issue with accessing group photos using application permissions.

HTTP 请求HTTP request

PATCH /me/photo/$value
PATCH /users/{id | userPrincipalName}/photo/$value
PATCH /groups/{id}/photo/$value
PATCH /me/contacts/{id}/photo/$value
PATCH /users/{id | userPrincipalName}/contacts/{id}/photo/$value
PATCH /me/contactfolders/{contactFolderId}/contacts/{id}/photo/$value
PATCH /users/{id | userPrincipalName}/contactfolders/{contactFolderId}/contacts/{id}/photo/$value

PUT /me/photo/$value
PUT /users/{id | userPrincipalName}/photo/$value
PUT /groups/{id}/photo/$value
PUT /me/contacts/{id}/photo/$value
PUT /users/{id | userPrincipalName}/contacts/{id}/photo/$value
PUT /me/contactfolders/{contactFolderId}/contacts/{id}/photo/$value
PUT /users/{id | userPrincipalName}/contactfolders/{contactFolderId}/contacts/{id}/photo/$value

请求标头Request headers

标头Header Value
AuthorizationAuthorization Bearer {token}。必需。Bearer {token}. Required.
Content-TypeContent-Type image/jpeg。必需。image/jpeg. Required.

请求正文Request body

在请求正文中,包括请求正文中照片的二进制数据。In the request body, include the binary data of the photo in the request body.

响应Response

如果成功,此方法返回 200 OK 响应代码。If successful, this method returns a 200 OK response code.

示例Example

请求Request

下面是一个请求示例。Here is an example of the request.

PUT https://graph.microsoft.com/v1.0/me/photo/$value
Content-type: image/jpeg

Binary data for the image

响应Response

下面是一个响应示例。注意:为了简单起见,可能会将此处所示的响应对象截断。将从实际调用中返回所有属性。Here is an example of the response. Note: The response object shown here may be truncated for brevity. All of the properties will be returned from an actual call.

HTTP/1.1 200 OK