Login   Register  
PHP Classes
elePHPant
Icontem

Problem with expiring token

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      PHP OAuth API  >  All threads  >  Problem with expiring token  >  (Un) Subscribe thread alerts  
Subject:Problem with expiring token
Summary:Problem with expiring token
Messages:3
Author:Michal Macierzynski
Date:2013-09-02 09:39:10
Update:2013-09-02 14:10:53
 

  1. Problem with expiring token   Reply  
Picture of Michal Macierzynski
Michal Macierzynski
2013-09-02 09:39:10
Hi,

I proceed with OAuth like in examples but I get some weird behaviour when I come back after 24 hours and test again.

So in general I got one class which invokes all needed OAuth code.

So all of those return success == 1
$success = $client->Initialize();
if ($success) {
$success = $client->Process();
if ($success) {


and then later:
case "Google":
$success = $client->CallAPI(
'https://www.googleapis.com/plus/v1/people/me',
'GET', array(), array('FailOnAccessError'=>true), $user);
//die('success:'.$success);

So all client_id, client_secret, scopre is set up correctly prevoiusly but CallAPI return some error in log:
[...] the access token is not set to a valid value [...]


When I try to debug ( and uncoment die statement then it says success:1 and next refresh with uncomenting die gives normal behaviour ( api call retrieves data )

Any idea what I'm doing wrong ?

  2. Re: Problem with expiring token   Reply  
Picture of Manuel Lemos
Manuel Lemos
2013-09-02 10:35:24 - In reply to message 1 from Michal Macierzynski
By default, the class stores tokens in session variables.

If you come in another day after having closed your browser, the original session is gone, so it is not possible to recover the original token.

To preserve tokens for a longer time, you need to use the mysqli_oauth_client.php or something similar that stores tokens in a database.

If you are storing the access token by yourself in a database, keep in mind that you also need to save and restore the expiry time and the refresh token values, so the class can renew expired tokens.

Also read this article if you want to access the API when the user is not present.

http://www.phpclasses.org/blog/package/7700/post/2-Offline-A ...

  3. Re: Problem with expiring token   Reply  
Picture of Michal Macierzynski
Michal Macierzynski
2013-09-02 14:10:53 - In reply to message 2 from Manuel Lemos
Thanks for advice. I've solved problem. It was because during re factoring of my class that wraps oauth client I removed


if ($this->exit)
exit;

Those 2 lines seems to be crucial for that narrow case