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

前端 未结 2 424
小鲜肉
小鲜肉 2021-02-04 16:58

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 fi

相关标签:
2条回答
  • 2021-02-04 17:32
    $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/

    0 讨论(0)
  • 2021-02-04 17:37

    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
    ));
    
    0 讨论(0)
提交回复
热议问题