Error on refreshing access token

Hello Team,

I am stored my token objects in DB.When refresh the token that time i used below code:

require_once ‘New_IS/vendor/autoload.php’;
$infusionsoft = new \Infusionsoft\Infusionsoft(array(
‘clientId’ => ‘XXXXXXXXXXXXXXXXXXX’,
‘clientSecret’ => ‘XXXXXXX’,
‘redirectUri’ => ‘http://abc.com/abc.php’,
));
$conn=mysqli_connect($host,$username,$password,$db);
$qrySel=“SELECT * FROM ZZZ WHERE id=1”;
$rsltOp=mysqli_query($conn,$qrySel);
$rowGetInfo=mysqli_fetch_assoc($rsltOp);
$infusionsoft->setToken(unserialize($rowGetInfo[“token”]));
$infusionsoft->refreshAccessToken();

for some time my code work fine, and then suddenly i am getting error like,

Fatal error: Uncaught exception ‘GuzzleHttp\Exception\ClientException’ with message 'Client error: POST https://api.infusionsoft.com/token resulted in a 400 Bad Request response:
{“error”:“invalid_grant”,“error_description”:“Invalid refresh token”}
’ in /home4/steamline/public_html/BWS/New_IS/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /home4/steamline/public_html/BWS/New_IS/vendor/guzzlehttp/guzzle/src/Middleware.php(66): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response))
#1 /home4/steamline/public_html/BWS/New_IS/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp{closure}(Object(GuzzleHttp\Psr7\Response))
#2 /home4/steamline/public_html/BWS/New_IS/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array)
#3 /home4/steamline/public_html/BWS/New_IS/vendor/guzzlehttp/promises/src/TaskQueue.php(47): GuzzleHttp\Promise in /home4/steamline/public_html/BWS/New_IS/vendor/infusionsoft/php-sdk/src/Infusionsoft/Http/GuzzleHttpClient.php on line 74

This is almost always caused by a bad refresh token. Typically this is due to unsafe threading when updating the token. A refresh token can only be used once to get a new access token. If two requests come into to update the token at the same time, then one will fail without proper thread synchronization.

Thanks @bradb

Can you give me a sample code for how to refresh the access token?

Thanks