基于this question,有没有办法检查用户是否使用基于PHP的Facebook SDK为应用授予了一组特定权限? 我浏览了API但找不到任何东西。
答案 0 :(得分:33)
$permissions = $facebook->api("/me/permissions");
然后使用if来检查您需要哪个权限
EX:
if (array_key_exists('publish_stream', $permissions['data'][0])) {
postToWall();
} else {
//Does not have permission
}
如果您使用的是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/
答案 1 :(得分:2)
在我没有访问令牌但拥有用户ID的情况下,这对我也有用:
$isGranted = $facebook->api(array(
"method" => "users.hasAppPermission",
"ext_perm" => "publish_stream",
"uid" => $facebook_id
));