我正在使用facebook-php-sdk
(github)在我的本地主机页面上登录Facebook,当我注销时,该页面没有重定向。
可以看到数组中的个人资料信息,即使在我按下注销后,页面上的数据也应该是空的,但它显示所有信息。
我使用了下面的代码,但它不是重定向
$logoutUrl = $facebook->getLogoutUrl(array('next' => 'http://google.com'));
<?php if ($user): ?>
<a href="<?php echo $logoutUrl; ?>">Logout</a>
<?php else: ?>
<div>
Login using OAuth 2.0 handled by the PHP SDK:
<a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
</div>
<?php endif ?>
使用 PHP SDK 获得成功登录的唯一方法是:将注销按钮重定向到函数并执行以下操作
private function do_facebook_logout() {
// Get an instance of the Facebook class
$facebook = $this->facebook_instance_factory();
// Destroy the session so that no Facebook data is held
$facebook->destroySession();
// Get the logout URL from the Facebook Class
$logout = $facebook->getLogoutUrl();
// Redirect the user to the logout url, facebook will redirect him to our page
wp_redirect( $logout );
}
我实际上在取消设置Facebook会话后重定向了用户。请记住,如果您在 Facebook 类的 instyance 中以编程方式设置访问令牌,您也必须使令牌无效