$maniaConnect = new \Maniaplanet\WebServices\ManiaConnect\Player(WSUSER, WSPASS);
...
$maniaConnectPlayer = $maniaConnect->getPlayer();
...
if ($maniaConnectPlayer) {
  $manialinks = $maniaConnect->getManialinks(); // <-- problem
  var_dump($maniaConnectPlayer);  // <-- no problem
}
Â
Within the same session I get the expected result, but after a while (~ 1-2 hours) the marked line throws an "Unauthorized" exception, I can however still access the player data.
What am I doing wrong or what should I do to fix this?
Last edited by zocka on 02 Jan 2015, 21:20, edited 1 time in total.
manialink minigame shatter
my manialink: zockaml
my maniaflash: maniaflash?zocka
The player data is cached in the session. So additional calls of getPlayer() do not result in additional ManiaConnect requests, but the cached values are used instead. This is only true for the player data; all other data is always re-requested from the webservices. (Dump $_SESSION after you authorized yourself and you should see your player data.)
So in your case, the player data is still present in the session (having getPlayer() not re-requesting it), yet the access token timed out meanwhile, having the following requests get declined. (FYI: The access token lasts 1 hour.)
To solve the problem, you must catch the MPWS exception, and check for 401 Not Authorized. If you encounter it, you must forward the user again to ManiaConnect to get a new access token and thus be able to re-request the data again.
@ Nadeo:
I noticed that the "refresh_token" seems to be always null. Can you confirm that this feature is currently not working/not supported?
The token you get on the Oauth has a different lifetime than the session of your application, so you have to check if it's still valid (with a try catch for instance) before making a call. If the call fails, you have to re-get a token.
About the refresh_token, you have to request the scope "offline" to get one, see the documentation.