codeigniter中的Facebook登录错误?

时间:2017-09-15 10:53:00

标签: php codeigniter facebook-login google-login

控制器:

ORDER BY

在这段代码中,我在同一页面上创建了facebook登录和google登录,例如google.php,google登录工作完美,facebook登录也正常工作,但是当我登录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);
}

我不知道为什么。那么,我该如何解决这个问题呢?请帮帮我。

谢谢

1 个答案:

答案 0 :(得分:0)

将Google身份验证和Facebook身份验证的逻辑分开,当您尝试使用Facebook $ _GET ['code']进行身份验证时,此变量会被设置,因为它会导致google身份验证代码,并且会显示错误消息:获取OAuth2访问令牌时出错,消息:'invalid_grant'