2012-11-04 55 views
3
工作我使用Facebook的使用CodeIgniter

和工作正常 但突然停止工作,是Facebook的改變任何東西Facebook登錄與笨突然停止

Facebook的功能

public function takofacebook($page = TRUE, $name = TRUE) { 

    if (isset($page) and (($page != TRUE) or ($page != 1)) and isset($name)) { 
     $data['page'] = $page; 
     $data['name'] = $name; 
    } 

    $this -> load -> library('fb'); 
    if (!$this -> fb -> is_connected()) { 
     redirect($this -> fb -> login_url(current_url())); 
    } 

    $fb_user = $this -> fb -> client -> api('/me'); 

    if (empty($fb_user)) { 
     $error = "FACEBOOK LOGIN FAILED - USER US EMPTY. FILE: " . __FILE__ . " LINE: " . __LINE__; 
     $this -> session -> set_flashdata('register_error', $error); 
    } else { 
     $this -> user -> set_facebook_id($fb_user['id']); 
     $user = $this -> user -> get_by_facebook(); 
     if (!empty($user) && !empty($user -> id) && is_numeric($user -> id)) { 

      //TODO: Make things a bit more secure here 
      //Login & Redirect home 

      $this -> _login($user -> id, 'facebook'); 
      $this -> load -> view('users/redirect_home2', $data); 
      return; 
     } 
    } 
    //Go to the registeration page 
    $this -> load -> view('users/redirect2', array('method' => 'facebook')); 
} 

/** 
* Logs user in with facebook 
*/ 

//tako facebook 
public function zangafacebook() { 



    $this -> load -> library('fb'); 
    if (!$this -> fb -> is_connected()) { 
     redirect($this -> fb -> login_url(current_url())); 
    } 

    $fb_user = $this -> fb -> client -> api('/me'); 

    if (empty($fb_user)) { 
     $error = "FACEBOOK LOGIN FAILED - USER US EMPTY. FILE: " . __FILE__ . " LINE: " . __LINE__; 
     $this -> session -> set_flashdata('register_error', $error); 
    } else { 
     $this -> user -> set_facebook_id($fb_user['id']); 
     $user = $this -> user -> get_by_facebook(); 
     if (!empty($user) && !empty($user -> id) && is_numeric($user -> id)) { 

      //TODO: Make things a bit more secure here 
      //Login & Redirect home 

      $this -> _login($user -> id, 'facebook'); 
      $this -> load -> view('users/redirect_home3'); 
      return; 
     } 
    } 
    //Go to the registeration page 
    $this -> load -> view('users/redirect3', array('method' => 'facebook')); 
} 
+2

很明顯,你有自己的Facebook庫(也許這個庫正在與官方SDK通信/擴展),請確保你有最新的[SDK版本](https://github.com/facebook/facebook-php -sdk),還嘗試添加圖api調用'$ fb_user = $ this - > fb - > client - > api('/ me');'嘗試catch語句以捕獲任何潛在的錯誤。 – ifaour

回答

1

我測試的PHP官方SDK來自我的CodeIgniter網站上的Facebook,它工作正常。 $ fb_user是否爲空?錯誤在哪裏?您是否使用Facebook的官方PHP SDK?要弄清楚這裏出了什麼問題,有很多變數。 像ifaour表明,這裏使用PHP官方SDK如果您還不:https://github.com/facebook/facebook-php-sdk/tree/master/src

滴在圖書館目錄中的文件並調用它通常

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

然後你就可以得到這樣Facebook的數據:

$fb_user = $this -> facebook -> api('/me'); 

再次我不確定你的錯誤在哪裏,你是否在這裏丟失了一個參數?

$ user = $ this - > user - > get_by_facebook($ fb_user ['id']);

這就是我在我的網站上所做的,它工作得很好。這也有好處,如果Facebook確實改變了您只需下載新SDK的任何內容,並且您的代碼應該保持不變。