1

我使用 codeigniter 平台来构建一个带有 facebook 登录 api 的网站。

当我第一次尝试使用 facebook 帐户登录时,它运行良好。

但是,如果我第二天再次使用 facebook 登录,我会收到此错误消息。

Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user.

看起来我没有进行重定向或没有获得新令牌。

这是 facebook 登录脚本。

function fblogin()
{

    // Get User Details
    $fb_id = $this->facebook->getUser();

    // User is found
    if( isset($fb_id) )
    {
        // Get Facebook User profile
        $user_profile = $this->facebook->api('/me');

        // User already has an account log them in
        if( $this->join->chk_user_facebook_id($fb_id) == USER_ID_EXIST) 
        {
            $u_data = $this->user->get_facebook_user_info($fb_id);

            //update facebook token
            $facebook_token = $this->input->get('code');
            $query = 'UPDATE '.T_USER_ACCOUNT.' SET u_facebook_token = "'.$facebook_token.'" WHERE u_facebook_id = "'.$fb_id.'" ';
            $this->db->query($query);

            //save session
            $l_data = array(
                SESSION_USERID      => $u_data[0]['u_id'],
                SESSION_USERNAME    => $u_data[0]['u_name'],
                SESSION_USEREMAIL   => $u_data[0]['u_email'],
                SESSION_USERAUTH    => $u_data[0]['u_auth']
            );
            $this->session->set_userdata($l_data);

            redirect('/home');
        }

        // This is a new user add them to users table and login
        else 
        {

            $facebook_id = $user_profile['id'];

            $j_data = array(
            'u_id' => $facebook_id,
            'u_facebook_id' => $facebook_id,
            'u_name' => $user_profile['name'],
            'u_first_name' => $user_profile['first_name'],
            'u_last_name' => $user_profile['last_name'],
            'u_facebook_token' => $this->input->get('code'),
            );

            $this->join->facebook_join($j_data);

            // Check if offline access
                $offline = $this->config->item('facebook_offline', 'tank_auth_social');

            // follow admin account
                $this->load->model('follow/following_model', 'following');
                $this->following->exec($facebook_id, GPON_DEFAULT_ID);

            // Get user information
                $data = $this->user->get_facebook_user_info($fb_id);

                $l_data = array(
                SESSION_USERID      => $data[0]['u_id'],
                SESSION_USERNAME    => $data[0]['u_name'],
                SESSION_USEREMAIL   => $data[0]['u_email'],
                SESSION_USERAUTH    => $data[0]['u_auth']
                );
                $this->session->set_userdata($l_data);

            // Find facebook friends in the service and follow them.
                $this->chk_facebook_friend();

            redirect('/account/welcome');
        }
    }
    else
    {
        redirect('/auth/login');
    }
}
4

1 回答 1

1

您应该替换if( isset($fb_id) )为,if( $fb_id) )因为该函数$this->facebook->getUser()在没有用户时返回 0。

于 2012-05-15T06:37:19.763 回答