1

我正在尝试这段代码:

$this->load->library('fbconnect');

    if ($this->fbconnect->user){

         echo "<pre>";  
         print_r($this->fbconnect->user);
         echo "</pre>";
    }else{
         echo "could not login at this tym";
     }

它始终显示“其他”条件的回声部分。'fbconnect' 是包含 facebookconnect 代码的库名称,'user' 正在从 fb 函数 'getUser()' 获取值

这是:'fbconnect.php'库的代码:

class Fbconnect extends Facebook{

    public  $user = NULL;
    public  $user_id = NULL;

    public function Fbconnect(){

        $ci=& get_instance();       
        $ci->config->load('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);
            }
        } 
    }
}
4

2 回答 2

0

登录功能可以放在控制器本身。添加 Facebook.php(facebook php sdk 文件)和 base_facebook.php(facebook php sdk 文件)到application/libraries

class Fbconnect extends CI_Controller{
    public function Fbconnect()
    {
       parent::__construct();
       $CI = & get_instance();
       $CI->config->load("facebook",TRUE);
       $config = $CI->config->item('facebook');
       $this->load->library('Facebook', $config);
    }

    function facebook_login()
    {
        $me = $this->facebook->getUser();

        if($me == 0){
        $loginUrl = $this->facebook->getLoginUrl();
        //Do the necessary with $loginUrl
        }else{
              try{
                   $user = $this->facebook->api('/me');
                   return $user; //or echo $user
                 }catch(FacebookApiException $e)
                 {
                   error_log($e);
                 }
      } 
   }
}

现在调用函数即http://yoursite.com/index.php/Fbconnect/facebook_login

于 2013-06-13T13:08:48.790 回答
0

检查日志文件或使用

if($this->user_id){
        try{
            $me = $this->api('/me');
            $this->user = $me;
        }
        catch(FacebookApiException $e){
            echo $e->getMessage();
        }
    } 

查看错误信息。

于 2013-06-13T13:11:57.193 回答