ManiaConnect doesn't work (bis)

Maniaplanet public API, ManiaConnect system and the open source PHP SDK.

Moderator: NADEO

User avatar
Kimi3
Posts: 510
Joined: 15 Jun 2010, 11:56
Location: France - Seine-et-marne (77)
Contact:

ManiaConnect doesn't work (bis)

Post by Kimi3 »

Hello all !

For my Manialink Motor, I still have an error on my script for Maniaconnect, and still don't understand why. Bo$$ and me tried a lot of things !

Code: Select all

<?php //Plages erreur : 800-809
// Authentification avec ManiaConnect :
require_once $dir . '/maniaplanet-ws-sdk/libraries/autoload.php';
define('API_USERNAME', $api_username);
define('API_PASSWORD', $api_password);
define('SCOPE', '');

try
{
	$trackmania = new \Maniaplanet\WebServices\ManiaConnect\Player(API_USERNAME, API_PASSWORD);
	
	// URLs to log in and out
	$loginURL = $trackmania->getLoginURL(SCOPE);
	$logoutURL = $trackmania->getLogoutURL();
	
	if(isset($_POST['logout']))
	{
		$trackmania->logout();
		header('Location: '.$logoutURL);
		exit;
	}

	// Retrive player information. If the user is not logged in, it will return false
	$player = $trackmania->getPlayer();

}
catch(\Maniaplanet\WebServices\Exception $e);
{
	$player = null;
}

$_SESSION['playerlogin'] = $player->login;
$_SESSION['nickname'] = $player->nickname;
$_SESSION['path'] = $player->path;
$_SESSION['player_id'] = $player->id;?>
The window to allow player to identify works, but then Invalid Manialink File.. ! The error is that the $player->login; variable return nothing. Do you have an idea ?
Last edited by Kimi3 on 18 Dec 2011, 15:42, edited 1 time in total.
Image
User avatar
TMarc
Posts: 15255
Joined: 05 Apr 2011, 19:10
Location: Europe
Contact:

Re: ManiaConnect doesn't work

Post by TMarc »

Is debugging possible? so you can display the $player structure with all its contents?
User avatar
m4rcel
Posts: 650
Joined: 15 Jun 2010, 11:12
Contact:

Re: ManiaConnect doesn't work

Post by m4rcel »

I think, the problem is that you catch any Exceptions, but you don't handle them the correct way.

Imagine you have the following situation:
Let ManiaConnect throw any error (the concrete error does not matter). You catch the raised exception (so far correct), and you assign null to $player... and right after that, you try to access this $player with ->id etc, which will generate PHP errors ("Cannot access field of null value" or sth like that), making your Manialink invalid.
I assume, that exactly this is your current situation.

My suggestion: Improve the error handling, printing the real error as nice message into the ManiaLink (because if an Exception is raised, _always_ something went wrong), and only if $player is really an object (check with is_object($player)), access its properties.


(Stupid question: Does $api_username and $api_password contain the username/password of your API user? ^^)
ImageImage
Image
User avatar
Boss-Bravo
Posts: 241
Joined: 10 Jan 2011, 18:26
Location: Devant mon PC :D
Contact:

Re: ManiaConnect doesn't work

Post by Boss-Bravo »

It's may be that, we don't verified that $player is null.
m4rcel wrote:(Stupid question: Does $api_username and $api_password contain the username/password of your API user? ^^)
Yes, they containt username and password :mrgreen: . It's not the main file, in the main file we include this file "connection.php" and before, we define the variables $api_username, $api_password and $dir correctly.

Thanks for your help. We will test this. ;)
User avatar
Kimi3
Posts: 510
Joined: 15 Jun 2010, 11:56
Location: France - Seine-et-marne (77)
Contact:

Re: ManiaConnect doesn't work

Post by Kimi3 »

Thanks ! We'll try this tonight :)
Image
User avatar
Boss-Bravo
Posts: 241
Joined: 10 Jan 2011, 18:26
Location: Devant mon PC :D
Contact:

Re: ManiaConnect doesn't work

Post by Boss-Bravo »

We tested if $player is null, is not null, for tried this, i maked that :

Code: Select all

catch(\Maniaplanet\WebServices\Exception $e);
{
   $player = null;
   echo 'player NULL';
}
   echo 'player non NULL';
$_SESSION['playerlogin'] = $player->login;
$_SESSION['nickname'] = $player->nickname;
$_SESSION['path'] = $player->path;
$_SESSION['player_id'] = $player->id;?>
And i see only 'player non NULL', so, $player is not null. After that, i tried to print_r($player) before SESSION, and it doesn't work, i don't understand where the error is. I think $player is not defined, but why ? :?
Thanks to help us. :thx:
User avatar
m4rcel
Posts: 650
Joined: 15 Jun 2010, 11:12
Contact:

Re: ManiaConnect doesn't work

Post by m4rcel »

Do you keep in mind, that $trackmania->getPlayer(); can also return false? (If the player does not have given the permission to his or her data, getPlayer() returns false instead of an object.)

That's why I said you should check with is_object($player), if $player is actual an object, before accessing it ;)
ImageImage
Image
User avatar
gouxim
Nadeo
Nadeo
Posts: 1186
Joined: 14 Jun 2010, 17:20

Re: ManiaConnect doesn't work

Post by gouxim »

The problem is that you catch exceptions, and then after that you use the $player var as if it was always an object.

But if you're not logged in yet, $player will be null (because of the catch block before) hence $player-login won't work.

You need to check if $player is null or not to handle both cases (logged in or not), just like we did in the example:

http://code.google.com/p/maniaplanet-ws ... dex.php#50
Please do not PM for support. Instead, create a thread so that everyone can contribute or benefit from the answer! 8-)
User avatar
Boss-Bravo
Posts: 241
Joined: 10 Jan 2011, 18:26
Location: Devant mon PC :D
Contact:

Re: ManiaConnect doesn't work

Post by Boss-Bravo »

I'm stupid, I did it for my manialink, but I forgot to do for m2 :teub:
It Works :mrgreen: Thanks to you Gouxim ;) :thx:
User avatar
Kimi3
Posts: 510
Joined: 15 Jun 2010, 11:56
Location: France - Seine-et-marne (77)
Contact:

Re: ManiaConnect doesn't work

Post by Kimi3 »

Thanks all for your help! :D
Image
Post Reply

Return to “Maniaplanet Web Services”

Who is online

Users browsing this forum: No registered users and 1 guest