Facebook OAuth 致命错误:未捕获 OAuthException:活动访问令牌
当我尝试使用 Facebook Connect 时收到此错误。
Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. thrown in /home/bakasura/public_html/ginger/app/vendors/facebook/facebook.php on line 543
脸书行动
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);
}
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 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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果未设置会话,您需要重定向到身份验证页面。我就是这样做的。
you need to redirect to authentication page if the session isn't set. I do it like this.