microsoftgraph / aspnetcore-connect-sample

[ARCHIVED] This ASP.NET Core MVC sample shows how to connect to Microsoft Graph using delegated permissions and the Azure AD v2.0 (MSAL) endpoint.
MIT License
123 stars 96 forks source link

Unable to get user photo #34

Closed teocomi closed 5 years ago

teocomi commented 5 years ago

Hello,

I'm unable to get the user photo. I get the following error:

Code: AuthenticationError
Message: Error authenticating with resource

Inner error

Stack Tracke:

   at Microsoft.Graph.HttpProvider.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
   at Microsoft.Graph.BaseRequest.SendRequestAsync(Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption)
   at Microsoft.Graph.BaseRequest.SendStreamRequestAsync(Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption)
   at MicrosoftGraphAspNetCoreConnectSample.Helpers.GraphService.GetPictureStream(GraphServiceClient graphClient, String email, HttpContext httpContext) in C:\code\aspnetcore-connect-sample\MicrosoftGraphAspNetCoreConnectSample\Helpers\GraphService.cs:line 99

Getting the user profile works fine.

Cheers

mark-szabo commented 5 years ago

Sorry for the late response! Which version of the graph API are you using? v1.0 or beta? What kind of account are you using to sign in? Personal, or Work or school account?

teocomi commented 5 years ago

Hello, yes it's v1 with a work account. I just tried again and now get more explicative error message:

{ "error": { "code": "ErrorItemNotFound", "message": "The photo wasn't found. REST APIs for this mailbox are currently in preview. You can find more information about the preview REST APIs at https://dev.outlook.com/.", "innerError": { "request-id": "54ec1525-e0b6-47d3-9cb0-5a8018625f37", "date": "2019-06-06T11:22:30" } } }

So guess something has to be enabled by system administrators to be able to get photos...

mark-szabo commented 5 years ago

Hmm, strange. Are you sure the user has a picture set up? I mean, if you go to portal.office.com for example, do you see the image on the top right?

teocomi commented 5 years ago

Hey, that was it! I'm pretty sure when I first opened I had also checked with accounts that had a picture set... But anyways, it's working now :) Thanks!