我在这里和网上搜索了我的问题,但我没有找到任何解决方案,这让我发疯,我不知道是什么问题。问题是,getUser() 函数总是返回 0。
这里是我的图书馆:
include(APPPATH.'libraries/facebook.php');
class Fbconnect extends Facebook{
public $user_id = null;
public $user = null;
function Fbconnect(){
$ci =& get_instance();
$ci->load->config('facebook',true);
$config = $ci->config->item('facebook');
parent::__construct($config);
$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);
}
}
}
}
这是控制器
function facebookRequest(){
$this->load->library('fbconnect');
$data = array(
'redirect_uri' => base_url().'home/handleFacebookRequest',
'scope' => 'email'
);
redirect($this->fbconnect->getLoginUrl($data));
}
function handleFacebookRequest(){
$this->load->library('fbconnect');
if($this->fbconnect->user){
echo '<pre>';
print_r($this->fbconnect->user);
}else{
echo "Login operation faild, try again later";
}
}
我使用配置文件来存储 appId 和 secrect
$config = array(
'appId' => 'xxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxx',
'cookie' => true
);