问题
I'm using the following code from this sample : here to get the user's thumbnail of there's account on office 365 tenant into windows 8.1 project XAML/c#
try
{
using (var dssr = await user.ThumbnailPhoto.DownloadAsync())
{
var stream = dssr.Stream;
var buffer = new byte[stream.Length];
await stream.ReadAsync(buffer, 0, (int) stream.Length);
ProfileImage = buffer;
}
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
However each time I try to bring user's thumbnail photo, I get the following error:
"Resource 'thumbnailPhoto' does not exist
or one of its queried reference-property objects are not present."
I'm using an Admin
user (Global Admin) in the add connected service and for sign in .
I searched for what they said on : here
"and these photos are actually stored in the Exchange mailbox itself rather than thumbnail Photo in Azure AD or your local AD (this may be the key piece you are looking for). So, it is most likely that the photo is stored in exchange and actually replicated or copied to the AAD."
but I didn't find any thing useful .
will you please help me
回答1:
I found out that the thumbnailPhoto attribute is populated in WAAD only if the synchronization happens from local Active Directory (e.g. using DirSync). So, by default, you will not find that field in the directory. Currently the only place that you would find the profile picture on is Exchange. So you are probably left with Download the picture from Exchange ( require authentication).
string completeUrl = "https://outlook.office365.com/ews/exchange.asmx/s/GetUserPhoto?email=your_email@domain.com&size=HR240x240";
WebRequest request = WebRequest.Create(completeUrl);
request.Credentials = new NetworkCredential("your_email@domain.com", "YourPassword");
HttpWebResponse response = (HttpWebResponse)(await request.GetResponseAsync());
if ((response.StatusCode == HttpStatusCode.OK ||
response.StatusCode == HttpStatusCode.Moved ||
response.StatusCode == HttpStatusCode.Redirect) &&
response.ContentType.StartsWith("image", StringComparison.OrdinalIgnoreCase))
{
// if the remote file was found, download oit
using (Stream inputStream = response.GetResponseStream())
{
byte[] buffer = new byte[4096];
int bytesRead;
do
{
bytesRead = await inputStream.ReadAsync(buffer, 0, buffer.Length);
} while (bytesRead != 0);
StorageFolder tempfolder = Windows.Storage.ApplicationData.Current.TemporaryFolder;
await tempfolder.CreateFileAsync("UserProfilePicture", CreationCollisionOption.ReplaceExisting);
StorageFile tempfile = await tempfolder.GetFileAsync("UserProfilePicture.png");
await FileIO.WriteBytesAsync(tempfile, buffer);
}
}
回答2:
I am not sure how to troubleshoot this with the Office 365 API, but if you want to take a look at an alterative route to get to the user thumbnail in the directory you can take a look at https://github.com/AzureADSamples/WebApp-GraphAPI-DotNet/ and specifically https://github.com/AzureADSamples/WebApp-GraphAPI-DotNet/blob/6577b3fc4fa0764a4ec375712cf795fb0b48fdad/WebAppGraphAPI/Controllers/UsersController.cs HTH V.
来源:https://stackoverflow.com/questions/26220856/office-365-api-azure-active-directory-bring-users-thumbnail-failed