How to renew access token with OAuth Refresh token?
<p>I'm creating simple app for Uber.<br>
And I've already solved 3 steps from this API: <a href="https://developer.uber.com/docs/authentication" rel="nofollow">https://developer.uber.com/docs/authentication</a> <br>
But now I want to refresh token (step 5).<br>
I receive access_token, refresh_token, expires_in values, and I can't understand how to set up timer to refresh user's token with refresh_token when the expires_in time expire.
<br> Here I provide my example of code, where I want to renew access token with refresh_token.  <br></p>

<pre><code>&lt;?php
session_start();

require_once 'uber_b.php';
require_once 'config.php';


if(isset($_GET['code'])) {
// try to get an access token
$code = $_GET['code'];
$url = 'https://login.uber.com/oauth/token';

/* 
* Create row for function setPostData (uber_b.php)
* All of this rows will be used to build our request
*/
$params = array(
    "code" =&gt; $code,
    "client_id" =&gt; $client_id,
    "client_secret" =&gt; $client_secret,
    "redirect_uri" =&gt; $redirect,
    "grant_type" =&gt; "authorization_code"
);
//create example of class
$request = new HttpPost($url);
//Connect this class with our settings
$request-&gt;setPostData($params);
//Send our request to Uber
$request-&gt;send(); 
//Receive response
$responseObj = json_decode($request-&gt;getHttpResponse());
//Execute parameters from answer
$user_token = $responseObj-&gt;access_token;
//Refresh token 
$refresh_token = $responseObj-&gt;refresh_token;
//Time for token
$expires_in = $responseObj-&gt;expires_in;

echo "User's token: " . $user_token;
echo "&lt;br&gt;";
echo "Refresh token is: " .$refresh_token ;
echo "&lt;br&gt;";
echo "Time: ".$expires_in;
echo "&lt;br&gt;";
echo "&lt;a href='order.php'&gt;Order a car&lt;/a&gt;";
}

//Refresh token
if(isset($responseObj))
{
        $exp_time = time()+2592000;
        try {
            //insert into database
            $stmt = $db-&gt;prepare('INSERT INTO token2 (exp_time)
                                      VALUES (:exp_time)
                                    ');
            $stmt-&gt;execute(array(
                ':exp_time' =&gt; $exp_time
            ));             
        } catch(PDOException $e) {
            echo $e-&gt;getMessage();
        }
}
if(time() &gt;= $exp_time)
{
//Parameters for Uber refresh token request(step 5)
$r_params = array(
    "client_id" =&gt; $client_id,
    "client_secret" =&gt; $client_secret,
    "redirect_uri" =&gt; $redirect,
    "grant_type" =&gt; "refresh_token",
    "refresh_token" =&gt; $refresh_token
    );
 $r_request = new RefreshToken($url);

 $r_request-&gt;setPostData($r_params);
 $r_request-&gt;send(); 
 $refresh = $refresh_token;
 $r_responseObj = json_decode($r_request-&gt;Refresh());

echo "New Refresh token: " . $r_responseObj-&gt;refresh_token;
echo "&lt;br&gt;";
}
?&gt;
</code></pre>

<p>As you see, I don't provide timer function, because I don't understand how to make it right.<br>
So, can you explain me how to correctly renew access_token using refresh_token? <br>
Maybe I have to use setcookie(), or something else to solve this task?</p>