我在启动 facebook 应用程序时使用
scope
参数请求一些额外的权限。有什么方法可以立即知道哪些权限被用户拒绝了?
这是一个简单的函数(根据我为简化 Facebook API 调用而编写的类进行修改),用于检查 Facebook 应用程序的“范围”与用户授予的权限之间是否存在差异。
function checkPermissions($scope, $facebook)
{
// Break the scope into an array
$scope = array_map('trim', explode(",", $scope));
// Get the users permissions from Facebook and put them in an array
$getUserPerms = $facebook->api('/me/permissions');
$userPerms = array_keys($getUserPerms['data'][0]);
// Permissions not granted is the difference between these arrys
$ungrantedPerms = array_diff($scope, $userPerms);
if ( ! empty($ungrantedPerms)) {
// authenticate user again
}
}
假设范围的格式如下:
$scope = 'email, user_about_me, user_likes, manage_pages, publish_stream';