2012-03-11 36 views

回答

3

這是一個簡單的函數(從我寫的簡化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'; 
+0

+1。我結束了使用類似的東西。 – 2013-03-08 17:31:07

+1

太棒了。我知道這很晚了(真的很晚),但我認爲它會幫助其他人,特別是考慮在Facebook API文檔中找到這種類型的信息有多困難! – 2013-03-08 17:45:13

相關問題