Download Horizon :: Staff Members :: TheTechGame.com :: XboxMB YouTube


Old 04-02-2011   #1 (permalink)

Austin's Avatar
Web Developer
Join Date: Dec 2010
Location: Washington
Posts: 1,345
Thanks: 2,059
Heart Parse XboxMB's API.

In this tutorial i'll show you how to easily parse XboxMB's API via PHP.

first off, let's define our variables.

PHP Code:
$api_url 'http://api.xboxmb.com/?u=';

// Use $_REQUEST to get either post or get data. In this case we will expect u to be the username
$username $_REQUEST['u']; 
Now, There are a couple of methods to retrieve the raw output in which the api gives. You can be lazy, and go for file_get_contents(); but CURL is proven to be faster so i'll show you CURL.

PHP Code:
//init the CURL request.
$info curl_init(); 

//set the session to retrieve from this url. the period concates both variables ($api_url.$username)
curl_setopt($infoCURLOPT_URL$api_url.$username);

//set the session to return data from the sessions's url.
curl_setopt($infoCURLOPT_RETURNTRANSFERtrue);

//sets the variable $result to contain the returned data.
$result curl_exec($info);

//closes the sessions connection.
curl_close($info); 
Some people don't have CURL installed on their servers, so file_get_contents() would be your best bet. Instead of the CURL above, use this.

PHP Code:
$result file_get_contents($api_url.$username); 
Now we have raw data of the requested username. Since the API's response is JSON we will have to decode it into usable form. The simplest and only method that i know of, is json_decode.

PHP Code:
//set the $result variable to be the decoded JSON. The 'true' parameter puts the data into an array. I HIGHLY recommend it, as if you have worked with arrays it makes parsing it a piece of cake.
$result json_decode($result,true);

//now that we have all the data given by the API in a easily accessible array, let's assign some variables.

//is the user valid?
$valid $result['Valid'];

//set the correctly formatted username (Capitalization).
$username $result['Username'];

//Have a title? return it, otherwise false.
$title = (empty($result['Title'])) ? false $result['Title'];

//is he staff?
$staff $result['Staff'];

//exact same concept as above.
$diamond $result['Diamond'];

//again.
$banned $result['Banned'];

//posts.
$posts $result['Posts'];

//thanks.
$thanks $result['Thanks'];

//the gamertag linked to their profile.
$gamertag $result['Gamertag'];  

//date user joined in date format ex. Month Day, Year, Time am/pm.
$joined date('F j, Y, g:i a',$result['JoinDate']);

//User id.
$UID $result['UserID']; 
You now have parsed data from the API. you can do whatever you want with it by echoing it where you desire. example.

PHP Code:
echo 'The users post count is '.$posts.'!'
will return something like 'The users post count is 4503!'.

There you have it.
__________________

Last edited by Austin; 10-21-2011 at 02:17 PM. Reason: Updated
Austin is offline
Reply With Quote


Old 04-02-2011   #2 (permalink)
Cheater912's Avatar
:D
Join Date: Jul 2010
Location: New York
Posts: 5,683
Thanks: 12,223
Default Re: Parse XboxMB's API.

Stickied. Nice post
__________________
Cheater912 is offline Send a message via Skype™ to Cheater912
Reply With Quote
The following users thanked this post: Austin, Chris Webby, RZRClanLeader, Supporter, Uzi, xFamous


Old 04-02-2011   #3 (permalink)
Banned
 
Join Date: Sep 2010
Location: ılılıEzLandılılı
Posts: 3,320
Thanks: 994
Default Re: Parse XboxMB's API.

wow stickied that fast!

nice post
xEzi is offline Send a message via AIM to xEzi Send a message via Yahoo to xEzi Send a message via Skype™ to xEzi
Reply With Quote


Old 04-03-2011   #4 (permalink)
Tracti0nz's Avatar
Rawr.
Join Date: Sep 2010
Location: United Kingdom
Posts: 2,419
Thanks: 756
Default Re: Parse XboxMB's API.

Thanks bro
__________________
Tracti0nz is offline Send a message via AIM to Tracti0nz
Reply With Quote
The following user thanked this post: Austin


Old 04-03-2011   #5 (permalink)
xFamous's Avatar
Join Date: Oct 2010
Posts: 2,844
Thanks: 703
Default Re: Parse XboxMB's API.

wow you got sticky ed that fast omg thats amazing
so is your post

Nice thread
__________________
Yo im lukee im heella chiill Not if u get on my bad side thoo but yeaa whats up
xFamous is offline Send a message via AIM to xFamous
Reply With Quote
The following user thanked this post: Austin




Old 04-03-2011   #6 (permalink)
Banned
 
Join Date: Sep 2010
Location: UK - till i die
Posts: 1,902
Thanks: 487
Default Re: Parse XboxMB's API.

now u fixed it it works
NukeZilla is offline Send a message via AIM to NukeZilla Send a message via MSN to NukeZilla
Reply With Quote


Old 07-19-2011   #7 (permalink)

Austin's Avatar
Web Developer
Join Date: Dec 2010
Location: Washington
Posts: 1,345
Thanks: 2,059
Default Re: Parse XboxMB's API.

Updated to suit updated API.
__________________
Austin is offline
Reply With Quote


Old 07-20-2011   #8 (permalink)
Regular Member
sgt frankieboy's Avatar
Join Date: Nov 2010
Location: Netherlands
Posts: 2,391
Thanks: 1,738
World XboxMB API Class

I took this php script and put it inside a easy to use PHP class if anyone want's it
here it is



You can now simply do something like this
PHP Code:
require_once "XboxMB.php";

$user = new XboxMB("[USERNAME]");

echo(
$user->Username " his post count is " $user->Posts "<br />");

$user->Load("[USERNAME]");

echo(
$user->Username " his post count is " $user->Posts); 
__________________


Minecraft World Editor - [BETA] YTMP
Programming Resources

Quote:
Originally Posted by Rich Cook
Programming today is a race between software engineers striving to build bigger and better
idiot-proof programs, and the Universe trying to produce bigger and better idiots.
So far, the Universe is winning.
sgt frankieboy is online now Send a message via ICQ to sgt frankieboy Send a message via AIM to sgt frankieboy Send a message via MSN to sgt frankieboy Send a message via Yahoo to sgt frankieboy Send a message via Skype™ to sgt frankieboy
Reply With Quote


Old 07-20-2011   #9 (permalink)
Banned
 
Join Date: Sep 2010
Location: UK - till i die
Posts: 1,902
Thanks: 487
Default Re: Parse XboxMB's API.

PHP Code:
    $xboxmbuser $data['Username'];
    
$xboxmbTitle $data['Title'];
    
$xboxmbStaff $data['Staff'];
    
$xboxmbBanned $data['Banned'];
    
$xboxmbPosts $data['Posts'];
    
$xboxmbThanks $data['Thanks'];
    
$xboxmbGamertag str_replace(" ""%20"$data['Gamertag']);
    
$xboxmbUserID $data['UserID'];
    
$xboxmbProfile 'http://www.xboxmb.com/avatars/' $xboxmbUserID .  '.gif'
I use that and that as the avatar


AMAZING

DO I GET BANNED

Last edited by NukeZilla; 08-14-2011 at 09:28 PM.
NukeZilla is offline Send a message via AIM to NukeZilla Send a message via MSN to NukeZilla
Reply With Quote


Old 11-13-2011   #10 (permalink)
Regular Member
 
Join Date: Nov 2011
Posts: 6
Thanks: 1
Default Re: Parse XboxMB's API.

The simplest and only method that i know of, is json_decode.

Last edited by Chris; 11-13-2011 at 11:22 AM.
xuandma is offline
Reply With Quote

Reply

Tags
api, php, xboxmb api

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 09:13 AM.


 

Powered by vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
COPYRIGHT (c) 2010 - 2012 - XboxMB - DESIGN BY:
EDENWEBS.COM