Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a user has granted a certain set of permissions to my PHP app?

Based on this question, is there a way to check if a user has granted a certain set of permissions to an app using PHP based Facebook SDK? I've browsed the API but couldn't find anything.

like image 973
Valentin Brasso Avatar asked Dec 12 '11 17:12

Valentin Brasso


People also ask

How do I give an app permission on Facebook?

Tap in the top right of Facebook. Scroll down and tap Settings. Go to the Permissions section and tap Apps and Websites. Go to Apps, Websites and Games and tap Edit.

What are Facebook permissions?

Permissions with Facebook Login. When a person logs into your app via Facebook Login you can access a subset of that person's data stored on Facebook. Permissions are how you ask someone if you can access that data. A person's privacy settings combined with what you ask for will determine what you can access.


2 Answers

$permissions = $facebook->api("/me/permissions");

then use the if to check which permission you need

EX:

if (array_key_exists('publish_stream', $permissions['data'][0])) {
    postToWall();
} else {
    //Does not have permission
}

If you are using FQL

$perms = $facebook->api(array(
    "method" => "fql.query",
    "query" => "SELECT read_stream,offline_access,publish_stream FROM permissions WHERE uid=me()"
        ));
echo "<ul>";
foreach ($perms[0] as $k => $v) {
    echo "<li>";
    if ($v === "1") {
        echo "<strong>$k</strong> permission is granted.";
    } else {
        echo "<strong>$k</strong> permission is not granted.";
    }
    echo "</li>";
}

http://www.masteringapi.com/tutorials/how-to-check-if-user-has-certian-permission-facebook-api/22/

like image 92
Mario Avatar answered Oct 05 '22 16:10

Mario


This also worked for me, in cases when I didn't have an access token, but had the user's ID:

$isGranted = $facebook->api(array(
    "method"    => "users.hasAppPermission",
    "ext_perm"   => "publish_stream",
    "uid"       => $facebook_id
));
like image 29
evanmcd Avatar answered Oct 05 '22 16:10

evanmcd