facebookarchive / php-graph-sdk

The Facebook SDK for PHP provides a native interface to the Graph API and Facebook Login. https://developers.facebook.com/docs/php
Other
3.17k stars 1.95k forks source link

Graph returned an error: This authorization code has been used. #1254

Open hminvozone opened 2 years ago

hminvozone commented 2 years ago

I am using the SDK 5.7 version, customer redirected to the facebook login page and redirected back successfully however see This authorization code has been used. error on redirected page.

I have checked this page https://developers.facebook.com/tools/accesstoken/ and I can see the access token

Can any one help?

$fb = new Facebook\Facebook([
   'app_id' => 'xxxxx',
   'app_secret' => 'xxxxxx',
   'default_graph_version' => 'v2.10',
  ]);

$helper = $fb->getRedirectLoginHelper($redirectUrl);
if (isset($_GET['state'])) {
    $helper->getPersistentDataHandler()->set('state', $_GET['state']);
}

$permissions = ['email']; // optional
if (isset($_GET['code'])) {
  try {
            $accessToken = $helper->getAccessToken();
        } catch (FacebookRequestException $e) {
            echo 'Request error: ' . $e->getMessage();
            exit;
        } catch(Facebook\Exceptions\FacebookResponseException $e) {
            // When Graph returns an error
            echo 'Graph returned an error: ' . $e->getMessage();
            exit;
        } catch(Facebook\Exceptions\FacebookSDKException $e) {
            // When validation fails or other local issues
            echo 'Facebook SDK returned an error: ' . $e->getMessage();
            exit;
        }  catch (Exception $e) {
            echo 'Generic error: ' . $e->getMessage();
            exit;
        }
} else {
  redirectUrl($helper->getLoginUrl($redirectUrl, $permissions));
}
hminvozone commented 2 years ago

@sergeychernyshev @zpao @killian @klausbreyer guys can you help me out?