├── LICENSE
├── README.md
├── composer.json
└── src
├── .htaccess
├── achievements.php
├── fetch_conversation.php
├── friends.php
├── games.php
├── includes
├── bootloader.php
├── classes
│ ├── api.class.php
│ ├── base.class.php
│ └── cache.class.php
├── cookies
│ └── index.php
├── kernel.php
└── logs
│ ├── debug.log
│ ├── error.log
│ └── stack_trace.log
├── index.php
├── profile.php
├── search.php
└── send_message.php
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 XboxLeaders
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #[XboxLiveAPI](http://xboxleaders.com)
2 | ###Simple & Powerful RESTful API For Xbox LIVE
3 |
4 | [](https://packagist.org/packages/xboxleaders/xboxliveapi) [](https://packagist.org/packages/xboxleaders/xboxliveapi) [](https://packagist.org/packages/xboxleaders/xboxliveapi) [](https://packagist.org/packages/xboxleaders/xboxliveapi)
5 |
6 | XboxLiveAPI is a simple and powerful RESTful API created to obtain data from Xbox LIVE, created and
7 | maintained by [Jason Clemons](http://about.me/jasonclemons) and [Alan Wynn](http://twitter.com/djekl).
8 | Stay up to date [@xboxleaders](http://twitter.com/xboxleaders).
9 |
10 | Get started at http://xboxleaders.com/get-started/!
11 |
12 | Please consider [donating to the project](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6ZHLXELDHACX6) to keep the servers alive!
13 |
14 | ##License
15 | - XboxLiveAPI source files are licensed under the MIT License:
16 | - http://opensource.org/licenses/mit-license.html
17 | - The XboxLiveAPI documentation is licensed under the CC BY 3.0 License:
18 | - http://creativecommons.org/licenses/by/3.0/
19 | - Attribution is not required, but much appreciated:
20 | - `Data Provided By XboxLeaders - http://xboxleaders.com`
21 | - Full details: http://xboxleaders.com/license/
22 |
23 | ## Requirements
24 | 1. [PHP](http://php.net/downloads.php) 5.4 or higher required
25 | - [cURL](http://php.net/curl)
26 | - [JSON](http://pecl.php.net/package/json)
27 | 2. [Apache](http://httpd.apache.org) 2.2 or higher required
28 | - mod_header
29 | - mod_expires
30 | - mod_rewrite
31 | 3. Caching Engines (Highly Recommended!)
32 | - [APC](http://pecl.php.net/package/apc)
33 | - [XCache](http://xcache.lighttpd.net)
34 | - [Memcached](http://memcached.org)
35 |
36 | ## Composer
37 | 1. Get [Composer](http://getcomposer.org)
38 | 2. Require xboxleaders/xboxliveapi `php composer.phar require xboxleaders/xboxliveapi`
39 | 3. Installation dependencies not available
40 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "xboxleaders/xboxliveapi",
3 | "description": "Simple & Powerful RESTful API for Xbox LIVE",
4 | "keywords": ["xbox", "xboxlive", "api", "rest"],
5 | "homepage": "http://xboxleaders.github.io/",
6 | "authors": [
7 | {
8 | "name": "Jason Clemons",
9 | "email": "jason@xboxleaders.com",
10 | "role": "Creator/Developer",
11 | "homepage": "http://about.me/jasonclemons"
12 | },
13 | {
14 | "name": "Alan Wynn",
15 | "email": "hello@alanwynn.me",
16 | "role": "Contributor/Developer",
17 | "homepage": "https://alanwynn.me"
18 | }
19 | ],
20 | "license": [
21 | "MIT"
22 | ],
23 | "require": {
24 | "php": ">=5.4.0"
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/.htaccess:
--------------------------------------------------------------------------------
1 | # Rewrite the new URL before anything else
2 | Options +FollowSymLinks
3 | RewriteEngine On
4 | RewriteRule ^1\.0/(.*)$ /api/$1 [R=301,NE,L,QSA]
5 | RewriteRule ^2\.0/(.*)$ /api/$1 [R=301,NE,L,QSA]
6 |
7 | # Set the proper headers and stuff
8 | Header unset Pragma
9 | FileETag None
10 | Header unset ETag
11 | ExpiresActive On
12 | ExpiresDefault A0
13 |
14 |
15 | ExpiresDefault A0
16 | Header set Cache-Control "no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform"
17 | Header set Pragma "no-cache"
18 |
19 |
20 | # Route to the proper handler
21 | RewriteRule ^achievements\.(json|xml)$ achievements.php?format=$1 [L,QSA]
22 | RewriteRule ^games\.(json|xml)$ games.php?format=$1 [L,QSA]
23 | RewriteRule ^profile\.(json|xml)$ profile.php?format=$1 [L,QSA]
24 | RewriteRule ^friends\.(json|xml)$ friends.php?format=$1 [L,QSA]
25 | RewriteRule ^search\.(json|xml)$ search.php?format=$1 [L,QSA]
26 |
27 | RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|OPTIONS|POST|PUT)
28 | RewriteRule .* - [F]
--------------------------------------------------------------------------------
/src/achievements.php:
--------------------------------------------------------------------------------
1 | output_headers();
20 | $gamertag = (isset($_GET['gamertag']) && !empty($_GET['gamertag'])) ? trim($_GET['gamertag']) : null;
21 | $gameid = (isset($_GET['gameid'])) ? (int)$_GET['gameid'] : null;
22 | $region = (isset($_GET['region']) && !empty($_GET['region'])) ? $_GET['region'] : 'en-US';
23 |
24 | if (!$api->logged_in) {
25 | echo $api->output_error(500);
26 | } else {
27 | if (empty($gamertag)) {
28 | echo $api->output_error(301);
29 | } elseif (empty($gameid)) {
30 | echo $api->output_error(302);
31 | } elseif ($api->check_culture($region) == false) {
32 | echo $api->output_error(305);
33 | } else {
34 | $data = $api->fetch_achievements($gamertag, $gameid, $region);
35 | if ($data) {
36 | echo $api->output_payload($data);
37 | } else {
38 | echo $api->output_error($api->error);
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/fetch_conversation.php:
--------------------------------------------------------------------------------
1 | output_headers();
20 | $gamertag = (isset($_GET['gamertag']) && !empty($_GET['gamertag'])) ? trim($_GET['gamertag']) : null;
21 | $region = (isset($_GET['region']) && !empty($_GET['region'])) ? $_GET['region'] : 'en-US';
22 | $sender = (isset($_GET['sender']) && !empty($_GET['sender'])) ? trim($_GET['sender']) : null;
23 |
24 | if (!$api->logged_in) {
25 | echo $api->output_error(500);
26 | } else {
27 | if (empty($gamertag)) {
28 | echo $api->output_error(301);
29 | } elseif (empty($sender)) {
30 | echo $api->output_error(309);
31 | } elseif ($api->check_culture($region) == false) {
32 | echo $api->output_error(305);
33 | } else {
34 | $data = $api->fetchConversationWith($gamertag, $region, $sender);
35 | if ($data) {
36 | echo $api->output_payload($data);
37 | } else {
38 | echo $api->output_error($api->error);
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/friends.php:
--------------------------------------------------------------------------------
1 | output_headers();
20 | $gamertag = (isset($_GET['gamertag']) && !empty($_GET['gamertag'])) ? trim($_GET['gamertag']) : null;
21 | $region = (isset($_GET['region']) && !empty($_GET['region'])) ? $_GET['region'] : 'en-US';
22 |
23 | if (!$api->logged_in) {
24 | echo $api->output_error(500);
25 | } else {
26 | if (empty($gamertag)) {
27 | echo $api->output_error(301);
28 | } elseif ($api->check_culture($region) == false) {
29 | echo $api->output_error(305);
30 | } else {
31 | $data = $api->fetch_friends($gamertag, $region);
32 | if ($data) {
33 | echo $api->output_payload($data);
34 | } else {
35 | echo $api->output_error($api->error);
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/games.php:
--------------------------------------------------------------------------------
1 | output_headers();
20 | $gamertag = (isset($_GET['gamertag']) && !empty($_GET['gamertag'])) ? trim($_GET['gamertag']) : null;
21 | $region = (isset($_GET['region']) && !empty($_GET['region'])) ? $_GET['region'] : 'en-US';
22 |
23 | if (!$api->logged_in) {
24 | echo $api->output_error(500);
25 | } else {
26 | if (empty($gamertag)) {
27 | echo $api->output_error(301);
28 | } elseif ($api->check_culture($region) == false) {
29 | echo $api->output_error(305);
30 | } else {
31 | $data = $api->fetch_games($gamertag, $region);
32 | if ($data) {
33 | echo $api->output_payload($data);
34 | } else {
35 | echo $api->output_error($api->error);
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/includes/bootloader.php:
--------------------------------------------------------------------------------
1 | 'john@example.com',
32 | 'password' => 'Password123',
33 | 'gamertag' => 'Major Nelson'
34 | )
35 | );
36 |
37 | /*!
38 | * Pick a random email to login
39 | */
40 | $account = $accounts[0];
41 | if (count($accounts) > 1) {
42 | $id = rand(0, (count($accounts) - 1));
43 | $account = $accounts[$id];
44 | }
45 |
46 | /*!
47 | * Define the account credentials
48 | */
49 | define('XBOX_EMAIL', $account['email']);
50 | define('XBOX_PASSWORD', $account['password']);
51 | define('XBOX_GAMERTAG', $account['gamertag']);
52 |
53 | /*!
54 | * Define some log file locations.
55 | */
56 | define('COOKIE_FILE', 'includes/cookies/' . XBOX_EMAIL . '.jar');
57 | define('DEBUG_FILE', 'includes/logs/debug.log');
58 | define('STACK_TRACE_FILE', 'includes/logs/stack_trace.log');
59 |
60 | /*!
61 | * Initiate the caching engine.
62 | */
63 | $cache = new Cache(CACHE_ENGINE);
64 |
--------------------------------------------------------------------------------
/src/includes/classes/api.class.php:
--------------------------------------------------------------------------------
1 | version . ':sendMessage.' . $gamertag;
39 |
40 | $data = $this->fetch_url($url);
41 | $post_data = '__RequestVerificationToken=' . urlencode(trim($this->find($data, ''))) . '&recipients=' . urlencode($recipients) . '&message=' . urlencode($message);
42 |
43 | $headers = array('X-Requested-With: XMLHttpRequest', 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8');
44 | $data = $this->fetch_url('https://account.xbox.com/' . $region . '/Messages/Send', $url, 10, $post_data, $headers);
45 |
46 | return json_decode($data, true);
47 |
48 | }
49 |
50 | /**
51 | * Fetch conversation with
52 | *
53 | * @access public
54 | * @var string $gamertag
55 | * @var string $region
56 | * @var string $sender
57 | * @return array
58 | */
59 | public function fetchConversationWith($gamertag, $region, $sender)
60 | {
61 | $gamertag = trim($gamertag);
62 | $url = 'https://account.xbox.com/' . $region . '/Messages/UserConversation?senderGamerTag=' . $sender;
63 | $key = $this->version . ':getMessages.' . $gamertag;
64 |
65 | $data = $this->fetch_url($url);
66 | $doc = new DOMDocument();
67 | if(!empty($sender) && !empty($gamertag)) {
68 | $doc->loadHtml($data);
69 | $xpath = new DOMXPath($doc);
70 | $postThumbLinks = $xpath->query("//div[@class='messageContent']");
71 |
72 | $i = 0;
73 | $array = array();
74 | $last_sender = "";
75 | foreach($postThumbLinks as $link) {
76 |
77 | $body = $this->find($link->ownerDocument->saveHTML($link),'
','
');
78 | $time = $this->find($link->ownerDocument->saveHTML($link),'','
');
79 | $sender = $this->find($link->ownerDocument->saveHTML($link),'','
');
80 |
81 | $array[$i]['message'] = $body;
82 | $array[$i]['time'] = $time;
83 | if($sender){
84 | $array[$i]['sender'] = $sender;
85 | $last_sender = $sender;
86 | }else{
87 | $array[$i]['sender'] = $last_sender;
88 | }
89 |
90 | $i++;
91 | }
92 | } else {
93 | return false;
94 | }
95 |
96 | return $array;
97 | }
98 |
99 | /**
100 | * Fetch profile information
101 | *
102 | * @access public
103 | * @var string $gamertag
104 | * @var string $region
105 | * @return array
106 | */
107 | public function fetch_profile($gamertag, $region)
108 | {
109 | $gamertag = trim($gamertag);
110 | $url = 'http://live.xbox.com/' . $region . '/Profile?gamertag=' . urlencode($gamertag);
111 | $key = $this->version . ':profile.' . $gamertag;
112 |
113 | $data = $this->__cache->fetch($key);
114 | if (!$data) {
115 | $data = $this->fetch_url($url);
116 | $freshness = 'new';
117 | $this->__cache->store($key, $data, 3600);
118 | } else {
119 | $freshness = 'from cache';
120 | }
121 |
122 | if (stripos($data, '