I am trying to figure out how to handle error created when a user de-authorizes my Facebook app. I'm using larval 5 and this is the current error I'm getting:
Error validating access token: The user has not authorized application
the access_token is being stored in current session. Is there a way i can use a try and catch statement or any clever solution, so that when I get an access_token that doesn't validate I can still continue with the rest of the code.
below is the code i'm using, it world great infill app gets reauthorized:
$token = Session::get('fb_user_access_token');
$permissionsToRequest = ([
'public_profile',
'publish_actions'
]);
$login_link_for_public_actions = $fb->getLoginUrl($permissionsToRequest, 'http://pms.dev:8000/facebook/publicactions/callback');
if (isset($token)) {
$fb->setDefaultAccessToken($token);
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get('/me?fields=permissions');
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
// Returns a `Facebook\GraphNodes\GraphUser` collection
$facebookuser = $response->getGraphUser();
$ty= json_decode($facebookuser);
$permissions = $facebookuser['permissions'];
$checked = '';
foreach ($permissions as $p) {
if ($p['permission'] == 'publish_actions' && $p['status'] == 'granted' ) {
$checked = 'checked';
}
}
} else {
$checked = null;
}
I narrowed it down to the error coming somewhere from the try catch statement:
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get('/me?fields=permissions');
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
i'm getting this error in my view : FacebookResponseException in FacebookResponseException.php line 89:
I tried dd() different values inside the catch statements but nothing changes. I think i'm grabbing the wrong exeption , not sure what else to do?