Tirupati Rao
Tirupati Rao

Reputation: 615

how to get profile images of other users using outlook rest image api

I was trying to build a small web application which has outlook office 365 login.

So I was able to get the image of the logged-in user using below APIs:

GET https://outlook.office.com/api/v2.0/me/photo
GET https://outlook.office.com/api/v2.0/Users('{user_id}')/photo

When I pass user_id of other users I am getting the below error.

{
  "error": {
    "code": "ErrorAccessDenied",
    "message": "Access is denied. Check credentials and try again."
  } 
}

But when I did the same thing in Azure Sandbox everything went well. I was able to get the images of all the users.

Am I doing anything wrong here?

Any help would be appreciated.

Upvotes: 0

Views: 3498

Answers (1)

Marc LaFleur
Marc LaFleur

Reputation: 33114

A couple of things to note:

  1. You should generally use Microsoft Graph rather than the Outlook REST API. While they functionally overlap, Microsoft Graph is the core Microsoft API going forward. Your calls (and auth token request) will be very similar:

    GET https://graph.microsoft.com/v1.0/me/photo/$value
    GET https://graph.microsoft.com/v1.0/users/{userPrincipalName}/photo/$value
    
  2. When authenticating a user, the proper term to use is "Sign in with Microsoft". This is generally shown using this image:

    Sign in with Microsoft Badge

    You can find full details in the Branding Guidelines for Application.

As for the specific error you've received here, you need to add the User.ReadBasic.All permission scope to your authorization request. I suspect you're only asking for User.Read at the moment. This will only allow you to access the current user's information. You need additional permissions before you can access other user's in the tenant.

Upvotes: 1

Related Questions