luc*_*uca 3 php sdk facebook login
从thinkdiff.net 教程开始, 我已经构建了一个带有facebook登录/注销链接的简单测试页面(本地环境).如果登录,我想要回显fb用户API.
我使用最新的facebook PHP SDK(v.2.1.2).
它似乎工作,但当我退出时,我收到此异常:
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] =>
)
Run Code Online (Sandbox Code Playgroud)
这是我的测试页面代码
$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>";
}
Run Code Online (Sandbox Code Playgroud)
谢谢
卢卡
我会尝试在注销时手动清除会话.在返回URL上放置一个GET参数,或使用不同的返回URL,然后执行以下操作:
$facebook->destroySession();
Run Code Online (Sandbox Code Playgroud)
问题是即使在用户注销后会话cookie仍然存在.当用户返回到您的页面时,您尝试使用该过期的会话来发出请求.祝好运.
| 归档时间: |
|
| 查看次数: |
10539 次 |
| 最近记录: |