Facebook OAuth Fatal error: Uncaught OAuthException: An active access token
I am getting this error when i try to use Facebook Connect.
Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. thrown 开发者_JAVA技巧in /home/bakasura/public_html/ginger/app/vendors/facebook/facebook.php on line 543
Facebook Action
function facebook($authorize = null) {
App::import('Vendor', 'facebook');
$facebook = new Facebook(array(
'appId'=> $this->__fbAppId,
'secret'=> $this->__fbSecret,
'cookie'=>true
));
$session = $facebook->getSession();
if(!empty($session) && ($authorize == null)){
$login_url = $facebook->getLoginUrl(array(
'next' => Router::url(array('action' => 'facebook', 'authorize'), true),
'cancel_url' => Router::url(array('action' => 'login'), true),
'req_perms' => 'email,publish_stream',
));
header("Location:".$login_url);
}
$userInfo = $facebook->api('/me');
if(!$userInfo){
$this->Session->setFlash('Facebook login failed');
$this->redirect(array('action' => 'login'));
}
$user = array(
'User' => array(
'first_name' => $userInfo['first_name'],
'last_name' => $userInfo['last_name'],
'username' => $userInfo['username'],
'email' => $userInfo['email'],
'user_group_id' => 1,
'status' => 'active'
),
'Oauth' => array(
'provider' => 'facebook',
'provider_uid' => $userInfo['id']
)
);
$this->oauthLogin($user);
}
you need to redirect to authentication page if the session isn't set. I do it like this.
if(!empty($session) && ($authorize == null)){
//blablabla
}
else {
echo "<script type='text/javascript'>top.location.href = '".$this->_facebook->getLoginUrl(array('req_perms' => 'email,read_stream,publish_stream'))."';</script>";
}
精彩评论