Only getPlayer() doesn't throw "Unauthorised" exception ?

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

Moderator: NADEO

Post Reply
User avatar
TStarGermany
Posts: 466
Joined: 15 Jun 2010, 11:05
Contact:

Only getPlayer() doesn't throw "Unauthorised" exception ?

Post 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 ?
Last edited by TStarGermany on 10 Jan 2013, 11:01, edited 1 time in total.
User avatar
magnetik
Posts: 1673
Joined: 01 Feb 2012, 19:13
Location: Bordeaux
Contact:

Re: Only getPlayer() doesn't throw "Unauthorised" exception

Post 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).
ManiaPlanet technical documentation portal (Dedicated, ManiaLink, ManiaScript, Titles...) -- contribute!
User avatar
TStarGermany
Posts: 466
Joined: 15 Jun 2010, 11:05
Contact:

Re: Only getPlayer() doesn't throw "Unauthorised" exception

Post 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.
Post Reply

Return to “Maniaplanet Web Services”

Who is online

Users browsing this forum: No registered users and 1 guest