Xbox Live Gamer Status
UPDATED December 1, 2009
Hey guys, just to let you know. If you were having troubles with the source code below, you may want to give it another go. The url for the API had changed and I hadn’t noticed it until now. Please copy and paste the code below into a new php file and give it a whir. Please let me know if you have any other problems. I am currently working on a very cool project that I think many of you will use in the future. Let’s just say that it will be the envy of all your xbox friends who don’t use Wordpress. Enjoy.
Xbox Live is a super cool gaming platform. Not only that, its a great way to interact with your friends and others on a social level. I have been appalled at the fact that the Xbox development team has not made it easier for us to let our friends know when we are connected to Xbox Live.
Sure you can login to xbox.com or possibly use your iPhone friends list application, but what about a way to display your Online Status anywhere on the web. Well here is your answer. After about of day of research and development I have come up with a solid solution that can be styled anyway you choose.
Unstyled Code:
It turns out that one of the Xbox developers, Duncan Mackenzie has written a very valuable script that gathers a ton of information about Xbox Live users including: their online status, what games they have played recently and their achievement scores in each game. The problem is, he doesn’t explain in detail how to use his “Gamertag API” feed.
After understanding what all cURL was all about and how to parse through XML files using SimpleXML, I finally came up with my solution.
Styled Code:
I advise you to take a look at my code and try it for yourself. I have also listed a few small requirements below the source code.
Also, be sure to install the PHP widget if you would like to run this code inside a widget on your sidebar.
Embed your Xbox Live status with PHP.
<?php
$ch = curl_init("http://xboxapi.duncanmackenzie.net/gamertag.ashx?GamerTag=YOURGAMERTAG");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
$data = curl_exec($ch);
curl_close($ch);
$xml = new SimpleXmlElement($data, LIBXML_NOCDATA);
foreach ($xml->PresenceInfo as $mystatus)
{
print '<div id="xboxlivestatus"><a href="' . $xml->ProfileUrl . '">' . $xml->Gamertag . '</a> is ' . $mystatus->StatusText . ' : ' . $mystatus->Info . '</div>';
}
?>
Requirements:
If you have any questions please leave a comment.


The 



Recent Comments