public function FacebookAuthManager::checkPermission in Social Auth Facebook 8
Makes an API call to check if user has granted given permission.
Parameters
string $permission_to_check: Permission to check.
Return value
bool True if user has granted given permission. False otherwise.
File
- src/
FacebookAuthManager.php, line 238
Class
- FacebookAuthManager
- Contains all Simple FB Connect logic that is related to Facebook interaction.
Namespace
Drupal\social_auth_facebookCode
public function checkPermission($permission_to_check) {
try {
$permissions = $this->client
->get('/me/permissions')
->getGraphEdge()
->asArray();
foreach ($permissions as $permission) {
if ($permission['permission'] == $permission_to_check && $permission['status'] == 'granted') {
return TRUE;
}
}
} catch (FacebookResponseException $ex) {
$this->loggerFactory
->get('social_auth_facebook')
->error('Could not check Facebook permissions: FacebookResponseException: @message', [
'@message' => json_encode($ex
->getMessage()),
]);
} catch (FacebookSDKException $ex) {
$this->loggerFactory
->get('social_auth_facebook')
->error('Could not check Facebook permissions: FacebookSDKException: @message', [
'@message' => $ex
->getMessage(),
]);
}
// We don't have permission or we got an exception during the API call.
return FALSE;
}