2017-09-15 87 views
0

控制器:codeigniter中的Facebook登錄錯誤?

public function login() 
{ 
    $userData = array(); 
    if($this->facebook->is_authenticated()) 
    { 
     $userProfile = $this->facebook->request('get', '/me?fields=id,first_name,last_name,email'); 
     $userData['oauth_provider'] = 'facebook'; 
     $userData['oauth_uid'] = $userProfile['id']; 
     $userData['firstname'] = $userProfile['first_name']; 
     $userData['lastname'] = $userProfile['last_name']; 
     $userData['email'] = $userProfile['email']; 
     $userData['password'] = rand(); 
     $userID = $this->user->checkUser($userData); 
     if(!empty($userID)) 
     { 
      $data['userData'] = $userData; 
      $this->session->set_userdata('userData',$userData); 
     } 
     else 
     { 
      $data['userData'] = array(); 
     } 
     $data['logoutUrl'] = $this->facebook->logout_url(); 
    } 
    else 
    { 
     $fbuser = ''; 
     $data['authUrl'] = $this->facebook->login_url(); 
    } 



    if($this->session->userdata('loggedIn') == true) 
    { 
     redirect('test/profile'); 
    } 
    if(isset($_GET['code'])) 
    { 
     $this->google->getAuthenticate(); 
     $gpInfo = $this->google->getUserInfo(); 
     $userData['oauth_provider'] = 'google'; 
     $userData['oauth_uid']  = $gpInfo['id']; 
     $userData['firstname'] = $gpInfo['given_name']; 
     $userData['lastname']  = $gpInfo['family_name']; 
     $userData['email']   = $gpInfo['email']; 
     $userData['password'] = rand(); 
     $userID = $this->user->checkUser($userData); 
     $this->session->set_userdata('loggedIn', true); 
     $this->session->set_userdata('userData', $userData); 
     redirect('test/profile'); 
    } 
    $data['loginURL'] = $this->google->loginURL(); 

    $data['student_id'] = $this->session->userdata('student_id'); 
    $this->load->view('header-inside',$data); 
    $this->load->view('login',$data); 
} 

在這段代碼中我創建Facebook登錄和同一個頁面上登錄谷歌就是其中的login.php登錄谷歌工作完全和Facebook登錄也工作,但它給了我有登錄像一些錯誤Facebook的。它會顯示一些錯誤,如:

Type: Google_AuthException 

Message: Error fetching OAuth2 access token, message: 'invalid_grant' 

我不知道爲什麼。那麼,我該如何解決這個問題?請幫幫我。

謝謝

+0

我也有這個問題,但它來自谷歌API,而不是Facebook。我建議分開這兩個,並再次檢查每個功能。 – Vladut

+0

谷歌身份驗證錯誤,未找到訪問令牌 –

回答

0

分開谷歌認證和Facebook驗證的邏輯,當您嘗試與Facebook $ _GET [「代碼」]由於它恩特雷里奧斯了谷歌的認證碼,並驗證該變量被置給出錯誤消息:錯誤提取OAuth2訪問令牌,消息:'invalid_grant'