使用php检查facebook权限

使用php检查facebook权限,php,facebook,sdk,Php,Facebook,Sdk,我正在尝试检查用户对我的站点所允许的权限,并且正在使用facebook SDK获取数组中的权限 array(1) { ["data"]=> array(3) { [0]=> array(2) { ["permission"]=> string(9) "installed" ["status"]=> string(7) "granted" } [1]=> array(2) { ["permission"]=> string(14) "publ

我正在尝试检查用户对我的站点所允许的权限,并且正在使用facebook SDK获取数组中的权限

array(1) { 
["data"]=> array(3) { 
[0]=> array(2) { 
["permission"]=> string(9) "installed" 
["status"]=>     string(7) "granted" } 
[1]=> array(2) { 
["permission"]=> string(14) "public_profile" 
["status"]=> string(7) "granted" } 
[2]=> array(2) { 
["permission"]=> string(15) "publish_actions" 
["status"]=> string(7) "granted" } } }
我已经找到了一些代码来搜索数组以找到特定的权限,但是我认为SDK在编写此代码后已经发生了更改

if( array_key_exists('publish_actions', $permissions['data'][0]) ) {
        // Permission is granted!
        // Do the related task
       $post_id = $facebook->api('/me/feed', 'post', array('message'=>'Hello World!'));
} else {
        // We don't have the permission
        // Alert the user or ask for the permission!
        header( "Location: " . $facebook->getLoginUrl(array("scope" =>    "publish_stream")) );
}


我正在寻找一种方法来搜索
publish\u actions
,并确定它是
拒绝的
还是
授予的

您只需将
权限['data']
数组转换为更易使用的数组

$arr = array();

foreach( $permissions['data'] as $v){

    $arr[$v['permission']] = $v['status'];
}

var_dump($arr);
然后稍微修改一下脚本:

if( array_key_exists('publish_actions', $arr) && $arr['publish_actions'] == 'granted' ) {
    // Permission is granted!
    // Do the related task
    $post_id = $facebook->api('/me/feed', 'post', array('message'=>'Hello World!'));
} else {
    // We don't have the permission
    // Alert the user or ask for the permission!
    header( "Location: " . $facebook->getLoginUrl(array("scope" => "publish_stream")) );
希望这是你问的。。。玩得开心