Is getplayer() failing?
Posted: 21 Jan 2013, 15:36
There must be some aspect I'm missing here. The problem is that the code below seems to fail setting up $player. I have the application as allowed on my player page and all. Infact the "login" button show up each time you restart ManiaPlanet it seems.
I've just started setting it up so I haven't really read it all but shouldn't the verification just pass as long as the player has accepted to let the application get access?
Oh and from the code above I use $authlabel to verify before letting users interact with anything. So far I've just setup a simple guestbook.
Also note that after you have pressed the login button you do get access and getplayer() passes until you restart ManiaPlanet again.
Code: Select all
<?php
// Change these values to match your MPWS user
define('MPWS_USER', 'NOWAY');
define('MPWS_PASS', 'NOWAYISAID');
define('MPWS_SCOPE', 'basic');
// Include the MPWS files
require('libraries/autoload.php');
try {
// Try to retrieve the data of the player
$mpwsPlayer = new \Maniaplanet\WebServices\ManiaConnect\Player(MPWS_USER, MPWS_PASS);
$player = $mpwsPlayer->getPlayer();
if (!$player) {
// If $player equals false, we need the player to grant access to his or her data,
// so we need to print the LoginURL
$loginURL = htmlspecialchars($mpwsPlayer->getLoginURL(MPWS_SCOPE));
$authLabel = true;
} else {
// If $player is not false, the player allowed accessing his or her data,
$authLabel = false;
}
} catch (\Maniaplanet\WebServices\Exception $e) {
$message = htmlspecialchars("[{$e->getHTTPStatusCode()} {$e->getHTTPStatusMessage()}] {$e->getMessage()}", ENT_QUOTES, 'UTF-8');
$error = '<label sizen="100 5" halign="center" text="Exception: '.$message.'" />';
}
?>
Oh and from the code above I use $authlabel to verify before letting users interact with anything. So far I've just setup a simple guestbook.
Also note that after you have pressed the login button you do get access and getplayer() passes until you restart ManiaPlanet again.