Reputation: 71
I create a UWP applications. i want to get user profile with Microsoft Account. i implement login function using web account manager.
I've tried to implement to see this. : https://msdn.microsoft.com/en-us/windows/uwp/security/web-account-manager
and I can get user name, id, account id, etc(Microsoft Account). but I can't get user profile image. I tried to use USER Class(using Windows.System.User), but I do not know how to connect the two items. User class: https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/UserInfo How to Get User profile picture in UWP Application?
Upvotes: 2
Views: 2168
Reputation: 10841
I can get user name, id, account id, etc(Microsoft Account). but I can't get user profile image.
After getting the access token, you can get the user profile image through another live api:
private async void GetUserProfileImageAsync(String token)
{
var photoApi = new Uri(@"https://apis.live.net/v5.0/me/picture?access_token=" + token);
using (var client = new HttpClient())
{
var photoResult = await client.GetAsync(photoApi);
using (var imageStream = await photoResult.Content.ReadAsStreamAsync())
{
BitmapImage image = new BitmapImage();
using (var randomStream = imageStream.AsRandomAccessStream())
{
await image.SetSourceAsync(randomStream);
myProfile.Source = image;
myProfile.Width = image.PixelWidth;
myProfile.Height = image.PixelHeight;
}
}
}
}
And XAML:
<Image Name="myProfile"/>
Notes: Live API has been replaced by OneDrive API. So it is strongly recommended that you use the OneDrive API instead of Live API during your development.
Upvotes: 6