I need to check if Facebook app
exist in Facebook's
database with APP-ID
and APP-SECRET
provided by users through form input. I tried doing it like this:
$apid = $_POST['appid'];
$apsec = $_POST['appsec'];
$fb = new Facebook\Facebook([
'app_id' => $apid,
'app_secret' => $apsec,
'default_graph_version' => 'v2.5',
]);
try{
$appData=$fb->get('/'.$apid, $apid.'|'.$apsec);
} 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;
}
$appData=$appData->getDecodedBody();
if(isset($appData)){
$_SESSION['app_name']=$appData['name'];
$_SESSION['app_image']=$appData['url'];
}else{
//should return some kind of error message
}
I thought that if I make this call to Graph API
from try block
, that it will return some kind of error message or anything that I could use, but instead it kills whole script. Then, I thought of examining only the app access token
, and I tried this:
$accessToken = new Facebook\Authentication\AccessToken($apid.'|'.$apsec);
$check = $accessToken ->isAppAccessToken();
var_dump($check);
But it returns true for any random inserted app-id
and app-secret
, so it's not really checking does app exists. Please help if you know how to solve this.