code has expired (within the last hour) dropbox

640 Views Asked by At

Hi everyone i am new in dropbox api (php version).

i am getting authCode using authorizeUrl, its working good for only one time if i reload page error message shows on

'HTTP status 400 {"error_description": "code has expired (within the last hour)", "error": "invalid_grant"} how to get permanent authCode from dropbox.

$appInfo = dbx\AppInfo::loadFromJsonFile("api-key.json");
$webAuth = new dbx\WebAuthNoRedirect($appInfo, "PHP-Example/1.0");

$authorizeUrl = $webAuth->start();

echo "1. Go to: " . $authorizeUrl . "\n";
echo "2. Click \"Allow\" (you might have to log in first).\n";
echo "3. Copy the authorization code.\n";
$authCode = "****************************************";

list($accessToken, $dropboxUserId) = $webAuth->finish($authCode);
print "Access Token: " . $accessToken . "\n";

$dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
$accountInfo = $dbxClient->getAccountInfo();

print_r($accountInfo);
1

There are 1 best solutions below

0
Arun Kumar On

Found the solution in this error

some steps to solve this problem

  1. go to Apps page Dropbox apps
  2. add your site or localhost link to OAuth 2 Redirect URIs
  3. next to generate access token, then copy the access token and use it .
  4. finally remove this lines

list($accessToken, $dropboxUserId) = $webAuth->finish($authCode); print "Access Token: " . $accessToken . "\n";

and paste directly in your access token into

$accessToken = "VTEp2cvkQ8************************************";

it's working perfectly