The Hack o blog

Reinventing the weel

Retrieving Xbox 360 Details via PHP

For a while now I have often pondered about how to get certain information from a persons gamercard off of Xbox Live, for example their gamerscore or the last 5 played games. I relied on an XML document provided free from a person called Duncan McKenzie to get this information but over time it became laggy, buggy and sometimes didn’t work at all and caused coding errors to be displayed on my pages… so naturally I wanted to change methods.

Since Xbox.com doesn’t like you screenscraping thier pages, and have prevented you from doing so for the better part, I thought to myself…. what can I use from Xbox that they provide to me for my site and I remembered, the gamercards.

The URL they provide you with (for example: http://gamercard.xbox.com/x2i4eva.card) allows you to display your gamercard on your own sites/blogs. They give you this information for you to use – so why not scrape this for information? So I made a code to get these things and here they are for you to use should you wish to. They are written in PHP.

Get a Persons Gamerscore

Getting this information seems to be the most popular request – people think that because it is their gamerscore, surely they should have access to it from outside of Xbox.com and other affilates, however since it is provided to you on the card in plain Text/HTML formal, it’s easier to get. There is a method which I have found to work – although there are probably easier ways to do it.

<?php
$html = file_get_contents("http://gamercard.xbox.com/".$_GET["a"].".card");

preg_match_all(
‘/<span >(.*?)<\/span><\/p><p>/s’,
$html, $gscore, PREG_SET_ORDER);

foreach ($gscore as $top_key => $g_info) {
$gamerscore = $gscore[$top_key][1];
}
echo $gamerscore;
?>

This scrapes the HTML code and looks for a specific part – the part with the gamerscore, and assigns it to an array, since there is only one entry we can create a variable called $gamerscore and assign the gamerscore number to it. The way we choose what gamertag to scan is the $_GET[“a”] part, this is done by using this after the URL: mypage.php?a=x2i4eva

Get a Persons Zone

A gamers Zone is basically the part of the Xbox Live Community they prefer to be involved with (either Pro, Recreational, Family or Underground). The level they choose is basically the type of people they are likely to get matched with in games. To get this information you can use the same methods as the gamerscore like so:

<?php
$html = file_get_contents("http://gamercard.xbox.com/".$_GET["a"].".card");

//Get Zone
preg_match_all(
‘/<p><span class=”XbcFLAL”>Zone<\/span><span class=”XbcFRAR”>(.*?)<\/span><\/p>/s’,
$html, $gzone, PREG_SET_ORDER);

foreach ($gzone as $top_key => $g_info) {
$zone = $gzone[$top_key][1];
}

echo $zone;
?>

Get a Persons Account Subscription

Either Gold or Silver depending on thier subscription type, this can be obtained like so:

<?php
$html = file_get_contents("http://gamercard.xbox.com/".$_GET["a"].".card");

//Get Account Type
preg_match_all(
‘/<div><h3 class=”XbcGamertag(.*?)”>/s’,
$html, $gacc, PREG_SET_ORDER);

foreach ($gacc as $top_key => $g_info) {
$acc = $gacc[$top_key][1];
}

echo $acc;
?>

Get a Persons Reputation

A persons reputation is depicted by 5 stars, 0 stars means they aren’t very reputable online and 5 stars means they are. However there are only 20 images in total meaning a 100% reputation would be 20. So we get the number 0-20 and multiply it by 5 to get the right amount. If you want you can create your own star images or use Xbox’s.

<?php
$html = file_get_contents("http://gamercard.xbox.com/".$_GET["a"].".card");

//Get Rep
preg_match_all(
‘/<span><img src=”(.*?)” \/><\/span>/s’,
$html, $grep, PREG_SET_ORDER);

foreach ($grep as $top_key => $g_info) {
$fullrep = $grep[$top_key][1];
$rep = (substr($fullrep, strlen($fullrep)-6, 2)*5);
}

echo $rep . “%”;
?>

Get a Persons Last 5 Games

The last 5 games that the user played are displayed on their gamercard, therefore we can get quite a bit from this – such as the icon of the game, a link to the games Xbox.com page and also the name of the game. For this we will deal with getting the names of the games like so:

<?php
$html = file_get_contents("http://gamercard.xbox.com/".$_GET["a"].".card");

//Get Last Played Games
preg_match_all(
‘/<img height=”32″ width=”32″ title=”(.*?)” alt=”” src=”.*?” \/>/s’,
$html, $ggames, PREG_SET_ORDER);

foreach ($ggames as $top_key => $g_info) {
echo $ggames[$top_key][1] . “<br />”;
}
?>

To get the images use this instead to get the urls then output them in IMG tags:

<?php
$html = file_get_contents("http://gamercard.xbox.com/".$_GET["a"].".card");

preg_match_all(
‘/<img height=”32″ width=”32″ title=”.*?” alt=”” src=”(.*?)” \/>/s’,
$html, $ggames, PREG_SET_ORDER);

foreach ($ggames as $top_key => $g_info) {
echo “<img src=\””.$ggames[$top_key][1] . “\” /><br />”;
}
}

NOTE: For games that have TM in the name or foreign characters – these might display wierdly so you might want to use the strreplace function to strip them out.

Please note that using these methods to retrieve such data is against the Xbox Live Terms of Service, therefore you agree to utilise them at your own risk. I am in no way responsible for any action taken against you or likewise, your account on the Live service should you use this.

Advertisements

2 responses to “Retrieving Xbox 360 Details via PHP

  1. kenny February 2, 2010 at 2:16 AM

    This is a great post I love it

  2. Free Xbox Live March 3, 2010 at 2:07 AM

    Your website is loading rather slow for me. Might just be my isp but i don’t know… anyways nice post. Very helpful, many thanks. Will be sure to bookmark your blog for future reference 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: