2012-03-11 2 views

답변

3

페이스 북 앱의 '범위'와 사용자가 부여한 권한 사이에 불일치가 있는지 확인하기위한 간단한 함수 (Facebook API 호출을 단순화하기 위해 작성한 클래스에서 수정 됨)입니다.

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. 나는 비슷한 것을 사용하여 끝났다. –

+1

굉장합니다. 저는 늦었습니다 (정말로 늦었습니다).하지만 페이스 북 API 문서에서 이런 유형의 정보를 찾는 것이 얼마나 힘든지를 고려할 때 다른 누군가를 도울 것이라고 생각했습니다! –

관련 문제