Facebook OAuth 致命错误:未捕获 OAuthException:活动访问令牌

发布于 2024-10-27 02:20:20 字数 1767 浏览 0 评论 0原文

当我尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

各自安好 2024-11-03 02:20:20

如果未设置会话,您需要重定向到身份验证页面。我就是这样做的。

    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>";      
    }

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>";      
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文