Office365 API - Pulling my userphoto

余生长醉 提交于 2019-12-22 11:32:52

问题


I have a simple web app that for the past month or so the following was working:

outlook.office365.com/api/beta/Me/userphotos('120x120')/$value

but now it returns:

{"error":{"code":"RequestBrokerOld-ParseUri","message":"Resource not found for the segment 'userphotos'."}}

I get the same error if I try any of the following:

https://outlook.office365.com/api/beta/Me/userphoto
https://outlook.office365.com/api/beta/Me/userphotos
https://outlook.office365.com/api/beta/Me/userphoto/$value

It is possible that my organisation has changed something to cause this? Or has there been a general change in how this request works?

In the same app, my other email and calendar requests all work fine, this is simply just a cosmetic problem of not displaying the users profile pic in the top corner.


回答1:


This is really ElioStruyf's answer.

The endpoint is now called "photo" and not "userphoto"

To get the photo information you use:

https://outlook.office365.com/api/beta/Me/photo

To get the photo you call

https://outlook.office365.com/api/beta/Me/photo/$value

To get list of all available photo sizes, use this API endpoint -

https://outlook.office.com/api/beta/me/Photos/

Sample response -

{
    "@odata.context": "https://outlook.office.com/api/beta/$metadata#Me/Photos",
    "value": [
        {
            "@odata.id": "https://outlook.office.com/api/beta/Users('John.Doe@contoso.com')/Photos('48X48')",
            "@odata.readLink": "https://outlook.office.com/api/beta/Users('John.Doe@contoso.com')/Photos('48X48')",
            "@odata.mediaContentType": "image/jpeg",
            "@odata.mediaEtag": "\"7A1F3A9D\"",
            "Id": "48X48",
            "Height": 48,
            "Width": 48
        },
        {
            "@odata.id": "https://outlook.office.com/api/beta/Users('John.Doe@contoso.com')/Photos('64X64')",
            "@odata.readLink": "https://outlook.office.com/api/beta/Users('John.Doe@contoso.com')/Photos('64X64')",
            "@odata.mediaContentType": "image/jpeg",
            "@odata.mediaEtag": "\"7A1F3A9D\"",
            "Id": "64X64",
            "Height": 64,
            "Width": 64
        },
        {
            "@odata.id": "https://outlook.office.com/api/beta/Users('John.Doe@contoso.com')/Photos('96X96')",
            "@odata.readLink": "https://outlook.office.com/api/beta/Users('John.Doe@contoso.com')/Photos('96X96')",
            "@odata.mediaContentType": "image/jpeg",
            "@odata.mediaEtag": "\"7A1F3A9D\"",
            "Id": "96X96",
            "Height": 96,
            "Width": 96
        },
        {
            "@odata.id": "https://outlook.office.com/api/beta/Users('John.Doe@contoso.com')/Photos('120X120')",
            "@odata.readLink": "https://outlook.office.com/api/beta/Users('John.Doe@contoso.com')/Photos('120X120')",
            "@odata.mediaContentType": "image/jpeg",
            "@odata.mediaEtag": "\"7A1F3A9D\"",
            "Id": "120X120",
            "Height": 120,
            "Width": 120
        },
        {
            "@odata.id": "https://outlook.office.com/api/beta/Users('John.Doe@contoso.com')/Photos('240X240')",
            "@odata.readLink": "https://outlook.office.com/api/beta/Users('John.Doe@contoso.com')/Photos('240X240')",
            "@odata.mediaContentType": "image/jpeg",
            "@odata.mediaEtag": "\"7A1F3A9D\"",
            "Id": "240X240",
            "Height": 240,
            "Width": 240
        },
        {
            "@odata.id": "https://outlook.office.com/api/beta/Users('John.Doe@contoso.com')/Photos('360X360')",
            "@odata.readLink": "https://outlook.office.com/api/beta/Users('John.Doe@contoso.com')/Photos('360X360')",
            "@odata.mediaContentType": "image/jpeg",
            "@odata.mediaEtag": "\"7A1F3A9D\"",
            "Id": "360X360",
            "Height": 360,
            "Width": 360
        },
        {
            "@odata.id": "https://outlook.office.com/api/beta/Users('John.Doe@contoso.com')/Photos('432X432')",
            "@odata.readLink": "https://outlook.office.com/api/beta/Users('John.Doe@contoso.com')/Photos('432X432')",
            "@odata.mediaContentType": "image/jpeg",
            "@odata.mediaEtag": "\"7A1F3A9D\"",
            "Id": "432X432",
            "Height": 432,
            "Width": 432
        },
        {
            "@odata.id": "https://outlook.office.com/api/beta/Users('John.Doe@contoso.com')/Photos('504X504')",
            "@odata.readLink": "https://outlook.office.com/api/beta/Users('John.Doe@contoso.com')/Photos('504X504')",
            "@odata.mediaContentType": "image/jpeg",
            "@odata.mediaEtag": "\"7A1F3A9D\"",
            "Id": "504X504",
            "Height": 504,
            "Width": 504
        },
        {
            "@odata.id": "https://outlook.office.com/api/beta/Users('John.Doe@contoso.com')/Photos('648X648')",
            "@odata.readLink": "https://outlook.office.com/api/beta/Users('John.Doe@contoso.com')/Photos('648X648')",
            "@odata.mediaContentType": "image/jpeg",
            "@odata.mediaEtag": "\"7A1F3A9D\"",
            "Id": "648X648",
            "Height": 648,
            "Width": 648
        }
    ]
}

To fetch actual blob of desired photo size, call this API -

https://outlook.office.com/api/beta/me/Photos('120X120')/$value



回答2:


Nothing's wrong with your organization's office 365 configuration. Outlook UserPhoto API has stopped working with the given endpoint. Unfortunately, they haven't updated the documentation yet. Let's hope it will be up soon or they will at least update documentation with new API endpoint.



来源:https://stackoverflow.com/questions/33406065/office365-api-pulling-my-userphoto

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!