简体   繁体   中英

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; before the getUser()

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

Note :

  1. Facebook PHP SDK utilizes the $_REQUEST variable while CodeIgniter purges the $_REQUEST variable for security reasons.
  2. To get around this, you may copy the content of $_GET to $_REQUEST before calling getUser() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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