简体   繁体   English

带有Codeigniter的Facebook登录集成未返回用户个人资料数据

[英]facebook login integration with codeigniter not returning user profile data

This is my code which I based on a video tutorial. 这是我基于视频教程编写的代码。 How can I get user profile data after login? 登录后如何获取用户个人资料数据? I am not getting any. 我什么都没有。

//controller //控制器

public function signin()
{
    $this->load->library('facebook');
    //   parse_str( $_SERVER['QUERY_STRING'], $_REQUEST );
    $user = $this->facebook->getUser();

    if($user)
    {
        try{
            $data['user_profile']=$this->facebook->api('/me');
        }
        catch(FacebookApiException $e)
        {
            $user = null;
        }
    }
    else
    {
        $this->facebook->destroySession();
    }        

    if($user)
    {
        $data['logout_url']= site_url('front_con/logout');  
    }
    else
    {
        $data['login_url']= $this->facebook->getLoginUrl( array('redirect_uri'=>site_url('front_con/signin'),
        'scope'=>array("email")));
    }
    // echo "kkksdf";
    $this->load->view('check',$data);
}


public function logout()
{  
    $this->load->library('facebook');
    $this->facebook->destroySession();
    redirect('front_con/signin');
}

//here is my view //这是我的观点

<?php if(@$user_profile): ?>
<?=$user_profile['name']?>
<a href="<?= $logout_url; ?>">Click here to logout</a>
<?php var_dump($user_profile);?>
<?php else:?>
<a href="<?= $login_url; ?>">Click here to login</a>
<?php endif; ?>

Just use $_REQUEST += $_GET; 只需使用$_REQUEST += $_GET; before the getUser() getUser()之前

$_REQUEST += $_GET; 
$user = $facebook->getUser();

Note : 注意事项

  1. Facebook PHP SDK utilizes the $_REQUEST variable while CodeIgniter purges the $_REQUEST variable for security reasons. Facebook PHP SDK使用$_REQUEST变量,而CodeIgniter出于安全原因清除$_REQUEST变量。
  2. To get around this, you may copy the content of $_GET to $_REQUEST before calling getUser() . 为了解决这个问题,您可以在调用getUser()之前将$_GET的内容复制到$_REQUEST

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM