简体   繁体   中英

How to get User profile picture using Web account manager with UWP

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM