Warning: Parameter 1 to wp_default_scripts() expected to be a reference, value given in /home/webgalli/public_html/blog/wp-includes/plugin.php on line 571

Warning: Parameter 1 to wp_default_scripts() expected to be a reference, value given in /home/webgalli/public_html/blog/wp-includes/plugin.php on line 571
How to check if required facebook permissions are provided by user - Team Webgalli Blog - Team Webgalli Blog
Request quote

How to check if required facebook permissions are provided by user

Posted on: May 18th, 2012 by Raez Mon 3 Comments

As social media is now become more powerful, all of the devs are forced to learn the facebook apps, twitter aps, API’s etc.. Facebook as it provides a lot of API’s and permissions, devs can request for any of them like publish_stream, read_stream etc to read personal information, likes, posts, to post update and many more.. But situations can happen when users wont provide these permissions.

Functionality of apps depend on these user data, so its important to check if certain permission(s) is granted by the user to the app. Here are a few php code snippets to check whether user has provided adequate permissions for the facebook Apps.

Using the facebook FQL (Facebook Query Language)

$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>";
}
echo "</ul>";

Using the facebook GraphAPI

With the new addition of permissions connections to user objects, you can check the permissions by

$permissions = $facebook->api("/me/permissions");
if( array_key_exists('publish_stream', $permissions['data'][0]) ) {
    // Permission is granted, post a hello world on the facebook wall!
    $post_id = $facebook->api('/me/feed', 'post', array('message'=>'Hello World!'));
} else {
    // We don't have the permission re request for the permission!
    header( "Location: " . $facebook->getLoginUrl(array("scope" => "publish_stream")) );
}

Using the Facebook RESTApi

$isGranted = $facebook->api(array(
    "method"    => "users.hasAppPermission",
    "ext_perm"   => "publish_stream",
    "uid"       => 579187142
));
if($isGranted === "1")
    echo "Permission granted!";
} else {
    echo "No permission granted!";
}

3 Responses

  1. Sushant says:

    nice and useful tip. just changed my site script to check for extended permissions. Thx for sharing.

  2. Kevin says:

    Hey!

    This is very useful – been looking all over for this answer.

    Do you know of a way that, once you’ve checked permissions, you can ask again for the user to grant permissions if they haven’t?

    Specifically, I’m trying to do this in a JS app, so, the simplest way is best.

    Thanks!

  3. Team Webgalli'an says:

    Just check the permissions again and alert them if they haven’t provided the new ones.