xbox-live

Accessing Raw Gamer Profile Picture


I am using the new XBox Live API for C# (https://github.com/Microsoft/xbox-live-api-csharp) for official access through a UWP app.

I am able to authenticate fine and reference the XBox Live user in context.

SignInResult result = await user.SignInAsync(); 
XboxLiveUser user = new XboxLiveUser();

Success! However, I can't seem to find an appropriate API call to return XboxUserProfile or XboxSocialProfile. Both of these classes contain URLs to the player's raw gamer pics. After reviewing MSDN documentation and the GH library it isn't clear to me how this is achieved. Any help is greatly appreciated.


Solution

  • The below sample should work if you meet the following pre requisits:

    1. Reference the Shared Project that contains the API from your project and don't reference the "Microsoft.Xbox.Services.UWP.CSharp" project
    2. Copy all source code files from the "Microsoft.Xbox.Services.UWP.CSharp" project into your project
    3. Include the Newtonsoft.Json NuGet package into your project

    Steps 1 & 2 are important as this allows you to access the "internal" constructors which otherwise would be protected from you.

    Code to retrieve the profile data:

            XboxLiveUser user = new XboxLiveUser();
            await user.SignInSilentlyAsync();
    
            if (user.IsSignedIn)
            {
                XboxLiveContext context = new XboxLiveContext(user);
                PeopleHubService peoplehub = new PeopleHubService(context.Settings, context.AppConfig);
                XboxSocialUser socialuser = await peoplehub.GetProfileInfo(user, SocialManagerExtraDetailLevel.None);
                // Do whatever you want to do with the data in socialuser
            }
    

    You may still run into an issue like I did. When building the project you may face the following error:

    Error CS0103 The name 'UserPicker' does not exist in the current context ...\System\UserImpl.cs 142 Active

    If you get that error make sure you target Win 10.0 Build 14393.