好吧,我正在尝试使用 codeigniter 使用 facebook 实现登录,当我调用 getUser() 函数时,我总是有 0,我尝试了所有可能的解决方案,但它们都不适合我,我不知道为什么,这是我的 facebook 库类:
<?php
include(APPPATH.'libraries/facebook/facebook.php');
class Fbconnect extends Facebook {
public $user = NULL;
public $user_id = FALSE;
public $fb = FALSE;
public $fbSession = FALSE;
public $appkey = 0;
public function Fbconnect(){
$ci =& get_instance();
$ci->config->load('facebook', TRUE);
$config = $ci->config->item('facebook');
parent::__construct($config);
parse_str( $_SERVER['QUERY_STRING'], $_REQUEST );
$this->user_id = $this->getUser();
$me = null;
if($this->user_id){
try{
$me = $this->api('/me');
$this->user = $me;
} catch(FacebookApiException $e){
error_log($e);
}
}
}
}
这里是我的主控制器:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Main extends CI_Controller {
public function index()
{
$this->load->view('index');
}
public function fb_request()
{
$this->load->library('fbconnect');
$data = array(
'redirect_uri' => site_url('main/handle_facebook_login'),
'scope' => array('email','user_birthday')
);
redirect($this->fbconnect->getLoginUrl($data));
}
public function handle_facebook_login()
{
$this->load->library('fbconnect');
$user = $this->fbconnect->user;
echo "<pre>";
print_r($user);
echo "</pre>";
if($user)
{
echo "<pre>";
print_r($user);
echo "</pre>";
}
else
{
echo "Could not login ... ";
}
}
}