Anirudh Ramanathan
Anirudh Ramanathan

Reputation: 46728

Detect if a user has denied any permission in my Facebook application

I am asking for a few extra permissions using the scope parameter when launching the facebook application. Is there any way I can know immediately which permissions have been denied by the user?

Upvotes: 2

Views: 3034

Answers (2)

Chris Hayes
Chris Hayes

Reputation: 127

Here is a simple function (modified from a class I wrote to simplify Facebook API calls) to check if there are discrepencies between the 'scope' of the Facebook app and the permissions granted by the user.

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
    }
}

Is assumes the scope is formatted in the following way:

$scope = 'email, user_about_me, user_likes, manage_pages, publish_stream';

Upvotes: 3

DMCS
DMCS

Reputation: 31870

Query: https://developers.facebook.com/tools/explorer/?method=GET&path=me%2Fpermissions

See https://developers.facebook.com/docs/reference/api/user/ for more information on the user object's permissions connection.

Upvotes: 1

Related Questions