We are releasing a new version of the SDK, so let's make a quick beta phase first. If you are using the 1.0 release of the SDK, it will still work as the API hasn't changed.
What has changed?
- It now uses namespaces, so you need PHP 5.3. The project now has the same architecture as ManiaLib and ManiaLive so it's easy to mix the 3 of them.
- OAuth 2.0 (experimental) support. That's a big thing ; it allows authentication via TMF account on both Websites and Manialinks, and it allows third party apps to access private information such as email etc. More on that later.
http://code.google.com/p/trackmania-ws- ... loads/list
How to migrate from 1.0 to 2.0
It's really simple. Let's look at an example.
This is the basic example from the 1.0 release:
Code: Select all
<?php
require_once '/path/to/trackmania-ws.php';
$tmPlayers = new TrackMania_Players('your_api_username', 'your_api_password');
$player = $tmPlayers->get('gou1');
?>
Code: Select all
<?php
require_once '/path/to/autoload.php';
$tmPlayers = new \TrackMania\WebServices\Players('your_api_username', 'your_api_password');
$player = $tmPlayers->get('gou1');
?>
The require statement:
Code: Select all
require_once '/path/to/trackmania-ws.php';
Code: Select all
require_once '/path/to/autoload.php';
Code: Select all
new TrackMania_Players();
new TrackMania_Xxxx();
new ManiaHome();
Code: Select all
new \TrackMania\WebServices\Players();
new \TrackMania\WebServices\Xxxx();
new \TrackMania\WebServices\ManiaHome();
OAuth 2.0
Introduction
Today we are introducing OAuth2.0 support on the TrackMania Web Services API! Here's two quotes that describe what OAuth does:
http://oauth.net/
http://en.wikipedia.org/wiki/OAuthAn open protocol to allow secure API authorization in a simple and standard method from desktop and web applications.
OAuth 2.0 is a standard protocol and is thuss beeing adopted by more and more API providers such as Facebook, Google, Microsoft, Twitter, etc. We believe that providing such technology on our API will help the community build better applications by providing well known & standardized building blocks.OAuth (Open Authorization) is an open standard for authorization. It allows users to share their private resources (e.g. photos, videos, contact lists) stored on one site with another site without having to hand out their credentials, typically username and password.
Let's imagine a few use cases for TrackMania. With OAuth 2.0 you will be able to:
- Securely authentify someone with his TrackMania Forever account on your Website or your Manialink
- Get access to protected information, provided the player gave your application the permission to do so ; for example you will be able to access the list of buddies, the online status, and maybe even the email.
- "Do stuff" on behalf of the player (once again, provided he gave you the permission), for example posting a notification on ManiaHome as if the player was posting it himself.
Here's how it works (the code of this example is in the SDK under /example/oauth2/basic/index.php)
First you go the page, and you're not logged in yet. So you have a "log-in link" (we will provide an official login button later if you want to use a button). When you click on the link, if you are not already logged-in on the player page, you are asked to do so. This is the authentication part. Then the player is asked to give his permission. The application can request different permissions (basic, buddies, email, etc.). This is the authorization part. When the player accepts, he's redirected to the application. Using the API, the application can retrieve a player object in a secure way (if the login is "gou1", the application is sure that it's actually that player). After that, the application have an access token that can be used to call different services.
How to create an OAuth2 application?
- Go to http://developers.trackmania.com/
- Login and go to the page to manage one of your API user
- Click of the "Request access to TMF game data" button if it's not already done
- Click on the "Create an OAuth2 application" and follow the instructions
How do players manage authorized applications?
It all takes place on the Player Home: http://home.trackmania.com/authorizations/
Basic code example
This is a very basic code example.
Code: Select all
<?php
require_once __DIR__.'/../../../src/autoload.php';
define('API_USERNAME', 'api_username');
define('API_PASSWORD', 'api_password');
define('SCOPE', '');
try
{
$trackmania = new \TrackMania\WebServices\OAuth2\Player(API_USERNAME, API_PASSWORD);
$loginURL = $trackmania->getLoginURL(SCOPE);
$player = $trackmania->getPlayer();
}
catch(\TrackMania\WebServices\Exception $e)
{
var_dump($e->getHTTPStatusCode(), $e->getHTTPStatusMessage(), $e->getMessage());
$player = null;
}
if($player)
{
var_dump($player);
}
else
{
echo '<a href="'.$loginURL.'">Login with your TMF account</a>';
}
?>
For now only those scopes are available:
- basic - Access your account information: Basic account information: login, nickname, zone, tags, rankings.
- buddies - Access your buddies: List of your buddies
- email - View your email: View the email address associated with your account, if there is one.
- online_status - Access your online status: Whether you are connected to the game or an online multiplayer server.
Maniaplanet
What about the Maniaplanet API?
It's not in production yet. But it will be exactly the same. It will be called the Maniaplanet Web Services, and we'll release the Maniaplanet Web Services SDK for PHP which will be pretty much the same as this one. So you can start experimenting with the TMF SDK, and you will be ready for Maniaplanet! I don't have a release date yet, but I believe it will be avaible during the summer.