I am trying to retrieve the picture of a user within bot code using the following url using a Bearer token
https://mytenant.sharepoint.com/_layouts/15/userphoto.aspx?size=S&username=john.doe@mytenant.com
When I check via a browser the picture shows up fine. When trying to retrieve it programmatically, it returns an image but its the default placeholder silhouette grey image.
I gave the app in AAD a good amount of permissions
Any idea what I am missing? Tried all options I could think of.
My code is as follows:
using (HttpClient httpClient = new HttpClient())
{
byte[] imageBytes = null;
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", bearer);
var responseMessage = await httpClient.GetAsync(@"https://mytenant.sharepoint.com/_layouts/15/userphoto.aspx?size=S&username=john.doe@mytenant.com");
imageBytes = responseMessage.Content.ReadAsByteArrayAsync().Result;
string filePath = "C:\\Data\\Trash\\MyImage.jpg";
File.WriteAllBytes(filePath, imageBytes);
}