3
votes

I have tried to following way enter image description here

but i got Error "The access token does not belong to application " i have checked lot of time in my app id and secrt id, app id is correct but This error shown again and again I didn't peridict this Error? and also i have tried following way also

https://graph.facebook.com/v2.2/oauth/access_token?grant_type=fb_exchange_token&client_id=CLIENT_ID &client_secret=SECRED CODE&fb_exchange_token=EAACEdEose0cBAJRZCZBIaDmW3oOO6SHaOkQLKdgyjp1evGoQ19mYcZCXu5wWLwZABJUbV77tjPjiE2pac2fDEmjM1tZAZB8hflSyERXFWIZB2DtzZAGSgVX6Ukb0ZAZAzd6pohnZBXU0T2aqYwf1umUxsfgHQXBNmM15yhdZBG2Br

1
Did you select your own app from the dropdown in Graph API Explorer?CBroe
yes, I have created a new app and get app id and secret code ...Balakumar B

1 Answers

5
votes

PHPsdk 5 and v2.8

$fb = new Facebook\Facebook([
  'app_id'                => 'xxxxxxxxx',
  'app_secret'            => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
  'default_graph_version' => 'v2.8',
]);

$helper = $fb->getRedirectLoginHelper();
try {

  $accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  // There was an error communicating with Graph
  echo $e->getMessage();
  exit;
}

$client = $fb->getOAuth2Client();
try {
  // Returns a long-lived access token
  $accessTokenLong = $client->getLongLivedAccessToken($accessToken);
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  // There was an error communicating with Graph
  echo $e->getMessage();
  exit;
}

if (isset($accessTokenLong)) {
  // Logged in.
  $_SESSION['facebook_access_token'] = (string) $accessTokenLong;
}

Reference url :https://www.sammyk.me/upgrading-the-facebook-php-sdk-from-v4-to-v5