Integrating XBox Live SDK

I have a very preliminar support of leaderboards in one of my games.

You first have to query the leaderboard. In example:

StatisticManager statsManager;

var query=new LeaderboardQuery();
statsManager.GetLeaderboard (user,leaderboardId,query);

afterwards you have to manually query statsManager with DoWork (in example, in every Update cycle, or through a Thread) which returns you different events.

Try/catch it, as DoWork can throw exceptions.

    var eventList=live.statsManager.DoWork();
    foreach (var ev in eventList)
        if (ev.EventType==StatisticEventType.GetLeaderboardComplete)
            var args=ev.EventArgs as LeaderboardResultEventArgs;
            if (args!=null && args.Result!=null)
                processLeaderboardResults (args.Result);

Inside processLeaderboardResults, you do a

foreach (var row in result.Rows)

and you have each leaderboard entry in those rows. row.GamerTag, row.Rank , …

What you do with those (i.e. put them in a list to display them ) it’s all up to you.

p.s. why the h… I can’t format the code? :slight_smile:

Thanks, this was what i needed.

DoWork() can throw exceptions too!? Dang, everything needs try/catch.

Also @KakCAT , I believe games can be set up in “multi-user mode” but I’ve never messed with it myself. Essentially your game needs to be structured that way from the start as it will affect how you handle Xbox Live (to my understanding).

Thanks, the link was what I was searching for.

It is indeed complicating a lot the sign in process and specially the savegames, I have to think wether using or not. After all, you can also control several gamepads without loging in.

Yeah, my game has a local coop mode but I just stick with the single user mode. The second player is essentially just playing as a guest on the main player’s account and any achievements they unlock together are just unlocked for the primary player.

To remove the “new XboxLiveUser()”-crash, I had to:

  1. Right click the primary project, click Store > Associate App with the Store

  2. On your StartUp project, right click and select Add > New Item.
    Select the Text File type and name it “xboxservices.config”.

Enter this:

       "TitleId" : "your title ID (JSON number in decimal)",
       "PrimaryServiceConfigId" : "your primary service config ID",

Right click on the file, select Properties and ensure that:
Build Action is set to Content, andCopy to Output Directory is set to Copy Always.

I dont have a TitleId or PrimaryServiceConfigId, but it worked anyway.

Also tested on Xbox, works there too, but the User instance is empty. My current theory is that my account needs to be authorized for development.


First of thank you everyone for your posts. I have had a nightmare of a time trying to find any decent documentation on how to integrate the Xbox Live SDK into an existing project (The old XNA framework was a million times better and had proper documentation) and these posts have helped me get closer to the solution. One edit that’s needed (probably because MS changed it and didn’t bother to make it backwards compatible) is that the xboxservices.config needs the following format

“PrimaryServiceConfigId”: “00000000-0000-0000-0000-000000000000”,
“TitleId”: 00000000,
“XboxLiveCreatorsTitle”: true,
“Scope” : “xbl.signin”

See for more information

Thanks everyone