Facebook PHP SDK错误验证访问令牌 [英] Facebook PHP SDK Error validating access token

查看:136
本文介绍了Facebook PHP SDK错误验证访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从thinkdiff.net开始教程我已经建立了一个简单的测试页面(本地env)与一个Facebook登录/注销链接。如果我要回显fb用户API。

starting from a thinkdiff.net tutorial I have built a simple test page (local env) with a facebook login/logout link.If logged in i want to echo out the fb user API.

Im使用最新的 Facebook PHP SDK(v.2.1.2)

它似乎工作,但是当我注销我收到这个例外:

It seems to work but when i logout I receive this exception:

FacebookApiException Object
(
[result:protected] => Array
    (
        [error] => Array
            (
                [type] => OAuthException
                [message] => Error validating access token: The session is invalid because the user logged out or because auth.expireSession was invoked.
            )

    )

[message:protected] => Error validating access token: The session is invalid because the user logged out or because auth.expireSession was invoked.
[string:Exception:private] => 
[code:protected] => 0
[file:protected] => C:\wamp\www\fb\facebook.php
[line:protected] => 543
[trace:Exception:private] => Array
    (
        [0] => Array
            (
                [function] => _graph
                [class] => Facebook
                [type] => ->
                [args] => Array
                    (
                        [0] => /me
                    )

            )

        [1] => Array
            (
                [file] => C:\wamp\www\fb\facebook.php
                [line] => 492
                [function] => call_user_func_array
                [args] => Array
                    (
                        [0] => Array
                            (
                                [0] => Facebook Object
                                    (
                                        [appId:protected] => 1819654718*****
                                        [apiSecret:protected] => a2fccb8e93638b50c8d6b2**********
                                        [session:protected] => 
                                        [signedRequest:protected] => 
                                        [sessionLoaded:protected] => 1
                                        [cookieSupport:protected] => 1
                                        [baseDomain:protected] => 
                                        [fileUploadSupport:protected] => 
                                    )

                                [1] => _graph
                            )

                        [1] => Array
                            (
                                [0] => /me
                            )

                    )

            )

        [2] => Array
            (
                [file] => C:\wamp\www\fb\fb.php
                [line] => 33
                [function] => api
                [class] => Facebook
                [type] => ->
                [args] => Array
                    (
                        [0] => /me
                    )

            )

    )

[previous:Exception:private] => 
)

这是我的测试页面代码

$fbconfig['appid']  = "18196**********";     
$fbconfig['api']  = "5c6910be575e4e688ac6d**********";     
$fbconfig['secret']  = "a2fccb8e93638b50c8d6b2**********"; 

try
{         
   include_once "facebook.php"; 
}     
catch(Exception $o)
{         
 echo '<pre>';         
 print_r($o);         
 echo '</pre>';     
}     
// Create our Application instance.     
$facebook = new Facebook(array('appId'  => $fbconfig['appid'],'secret' =>    $fbconfig['secret'],'cookie' => true));       

$session = $facebook->getSession();       
$fbme = null;     
// Session based graph API call.     
if (!empty($session)) 
{       
  d($session);
  try 
  {         
    $uid = $facebook->getUser();         
    $fbme = $facebook->api('/me');       
  } 
  catch (FacebookApiException $e) 
  {           
    d($e);       
  }    
}      
function d($d)
{         
echo '<pre>';         
print_r($d);         
echo '</pre>';     
} 


if ($fbme) 
{   
  $logoutUrl = $facebook->getLogoutUrl(); 
  echo"<a href='{$logoutUrl}'>logout</a>";
  d($fbme);
} 
else 
{   
  $loginUrl = $facebook->getLoginUrl(array('req_perms' => 'email,read_stream,user_birthday')); 
  echo"<a href='{$loginUrl}'>login</a>";
}

谢谢

Luca

推荐答案

我会尝试在注销时手动清除会话。将GET参数放在返回网址上,或使用不同的返回网址,然后执行以下操作:

I would try manually clearing the session on logout. Put a GET parameter on the return url, or use a different return url, and then do this:

$facebook->destroySession();

问题是即使在用户注销后,会话Cookie仍然存在。当用户返回到您的页面时,您尝试使用该过期会话来发出请求。祝你好运。

The problem is that the session cookie persists even after the user is logged out. When the user returns to your page you are trying to use that expired session to make requests. Good luck.

这篇关于Facebook PHP SDK错误验证访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆