How To: Add Xbox Live info to your website

If you're designing your own website at the moment, then read on to find out how to add live, up-to-date information on your Gamertag to your site.  If you're not making a website then scroll down and read about Kylie.

A blogger by the name of Duncan Mackenzie has written a script that fetches all kinds of information about your gamertag... or anyone's gamertag, for that matter.  Here's how to do it.

First off, you'll need something to create ASP.NET web pages.  I use Microsoft's Visual Web Developer 2008 Express - its free, and brilliant, so download away.  I recommend finding some tutorials and introductions so familiarise yourself with the software and/or web developing first, though if you're reading this then I'm sure you already have.

  1. In any .aspx page, add an XML Data Source as follows:
    <asp:XmlDataSource ID="GamerCardSource" runat="server" DataFile="http://duncanmackenzie.net/services/GetXboxInfo.aspx?GamerTag=CreepinJesus" XPath="XboxInfo" EnableCaching="false" />
    • For the [ID] field, enter a unique (to the page) name for the control (anything you like).
    • For the [GamerTag], put in the gamertag you wish to fetch info for.
    • The [XPath] tag is a bit more complicated.  This is, in a way, the 'starting level' of the data-fetching.  Take a look at the structure of the XML file that gets fetched.  I use the XPath value "XboxInfo" because all the other elements of the page are contained within this tag (it saves me having to put "XboxInfo/" at the beginning of every data field later on).
    • Finally, make sure that EnableCaching is set to false.  This is important if you want the information to be up to date.  You can also set a CacheDuration variable to set a time interval for refreshing the source; for example, every 30 seconds.
  2. Next, stick in a FormView or a data-bound control of your choice:
    <asp:FormView ID="[ID]" runat="server" DataSourceID="[IDofXmlSource]">
    • Again, the [ID] is up to you.
    • For DataSourceID, give the ID of the XmlDataSource control from step 1.
  3. Fill in a <ItemTemplate> inside the FormView.  Format this however you like, using standard HTML tags (or even more ASP.NET controls).  When it comes to inserting databound fields, you need to use server-side script tags as follows (example is in C#):
    <p>I am: <%# XPath("PresenceInfo/StatusText") %></p>
    • The XPath command returns the value of the specified field (or XML Path).  Notice in the XML structure that the field, "StatusText" is contained within "PresenceInfo", hence the slash "/" in the path.  Think of it as a regular folder structure on your computer: "text.txt" is in the "Files" folder, so the path is "Files/text.txt".
    • This example will render on the page as: "I am Online" or "I am Offline", or (Away/Busy).

That's about it really.  This covers the basics, so I'll let you finish it off to your liking.  Happy coding!

Rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Posted by CreepinJesus on 6/3/2008 at 9:37 PM

Tags: , , ,
Categories: How-To | Xbox
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Comments are closed - no more comments can be made to this post.