我使用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');
}
}
答案 0 :(得分:1)
您应该将if( isset($fb_id) )
替换为if( $fb_id) )
,因为当没有用户时,函数$this->facebook->getUser()
会返回0。