Reputation: 2736
I'm querying the user's photo metadata and then use the ID from the metadata to query the actual photo:
https://graph.microsoft.com/v1.0/users/<user id>/photo
returns
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('<user id>')/photo/$entity",
"@odata.mediaContentType": "image/jpeg",
"@odata.mediaEtag": "W/\"...\"",
"id": "default",
"height": 64,
"width": 64
}
Note that its ID is default
. When I then try to get the content using https://graph.microsoft.com/v1.0/users/<user id>/photos/default/$value
, graph returns HTTP 400 with
{
"error": {
"code": "ErrorInvalidImageId",
"message": "The image ID is not valid",
"innerError": {
"date": "2021-12-02T14:59:49",
"request-id": "...",
"client-request-id": "..."
}
}
}
If I replace default
to 64x64
(the photo's dimensions from the metadata) in the above URL, everything's fine, i.e. https://graph.microsoft.com/v1.0/users/<user id>/photos/64x64/$value
returns the photo.
For many users the ID returned from https://graph.microsoft.com/v1.0/users/<user id>/photo
looks like 64x64
and this sort of IDs always work.
Why does Graph return default
for some users and how should I handle it? Is it safe to create the an ID from width and height whenever I get default
?
Upvotes: 0
Views: 337
Reputation: 15906
We may refer to the official document to find the reason for this scenario.
If we call the url /users/<user id>/photo
to get the metadata of the photo, we will get profilePhoto
as the response object which contains id, height, width
and the id is made up of height and width.
Then let's see this feature of the api, it is designed for querying the metadata with a specific photo size, so if the id stands for the photo size, we can use id as the query parameter, but if the id is some other value, it will not work here.
My idea on your case is that the api is designed for using photo size as the query parameter and we may always use the height and the width as the query parameter all the time so that we don't need to check if it returns a correct id for querying.
Upvotes: 1