Page 1 of 1
Only getPlayer() doesn't throw "Unauthorised" exception ?
Posted: 10 Jan 2013, 04:48
by TStarGermany
Code: Select all
"define('SCOPE', 'basic email buddies');
$maniaconnect = new \Maniaplanet\WebServices\ManiaConnect\Player(API_USERNAME, API_PASSWORD);
$player = $maniaconnect->getPlayer();
$buddies = $maniaconnect->getBuddies();
$email = $maniaconnect->getEmail();
Although permission is granted, getEmail() and getBuddies() always throw exception, even when they come before getPlayer() in the code lines... even the pure "
dumb example" does not work and throws the same exception.
Fatal error: Uncaught exception 'Maniaplanet\WebServices\Exception' with message 'Unauthorized' in /www/htdocs/XXX/login/maniaplanet-ws-sdk/libraries/Maniaplanet/WebServices/HTTPClient.php:338
Stack trace:
#0 /www/htdocs/XXX/login/maniaplanet-ws-sdk/libraries/Maniaplanet/WebServices/ManiaConnect/Client.php(287): Maniaplanet\WebServices\HTTPClient->execute('GET', '/player/buddies...', Array)
#1 /www/htdocs/XXX/login/maniaplanet-ws-sdk/libraries/Maniaplanet/WebServices/ManiaConnect/Player.php(81): Maniaplanet\WebServices\ManiaConnect\Client->executeOAuth2('GET', '/player/buddies...')
#2 /www/htdocs/XXX/login/index.php(11): Maniaplanet\WebServices\ManiaConnect\Player->getBuddies()
#3 {main}
thrown in <b>/www/htdocs/XXX/login/maniaplanet-ws-sdk/libraries/Maniaplanet/WebServices/HTTPClient.php on line 338
Is Marcel's Post (
HERE) related ? What can I change to make this work ?
Re: Only getPlayer() doesn't throw "Unauthorised" exception
Posted: 10 Jan 2013, 10:22
by magnetik
I think that during your test, you got a token without the "email" or "buddies" permissions and you are trying to get the buddies and email without the right scope.
Try log-out and log-in again to get the good scope.
(I tried both dumb, minimal and basic example and it worked fine).
Re: Only getPlayer() doesn't throw "Unauthorised" exception
Posted: 12 Jan 2013, 08:53
by TStarGermany
Using the SDK is horror but at least I somewhat found out what is responsible for the exception.
The problem seems to be that the "if ($player)" check is still true/valid, even if important cookies from maniaplanet.com could have been deleted in the meantime (manual or automatically).
And then, if I try to call anything with like "$player->login" or so, the exception error occurs. Nothing in the scripts understand that the connection between the MPWS and my website is broken/data is missing.
Only after deleting ALL related cookies on my site AND maniaplanet.com (ws/mp02...), a new connection attempt can be made without errors.
This is not really the WS's fault, because it requires user action (or browser automation) to trigger this behaviour, but I don't want errors showing up on my site.
So I decided to let my script call "new \Mania.." conditionally (by extra parameter in the redirection URI), grab all data as quickly as I can,store it on my site and kill any connection to maniaplanet.com. Not perfect, but still pretty safe.