【问题标题】:Check facebook permissions with php用php检查facebook权限
【发布时间】:2014-07-04 20:09:31
【问题描述】:

我正在尝试检查用户对我的网站允许的权限,并正在使用 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_actions 并确定它是declined 还是granted

【问题讨论】:

    标签: php facebook sdk


    【解决方案1】:

    您只需要将permission['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")) );
    

    希望这是你所要求的...玩得开心

    【讨论】:

      猜你喜欢
      • 2015-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多