我花了好几个小时寻找解决这个问题的方法,但找不到适合我的方法。当我在我的站点上单击“注销”时,用户信息仍然可见并且注销按钮仍然显示。这是代码:
require 'facebook-php-sdk/src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'xxxx',
'secret' => 'xxxx',
));
// Get User ID
$user = $facebook->getUser();
var_dump($user);
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
// Login or logout url will be needed depending on current user state.
if ($_GET['logout'] == "yes") {
setcookie('fbs_'.$facebook->getAppId(), '', time()-100, '/', 'http://gno.....ment/index.php');
session_destroy();
header("Location: ".$_SERVER['PHP_SELF']."");
}
if ($user_profile) {
$logoutUrl = $facebook->getLogoutUrl;
} else {
$loginUrl = $facebook->getLoginUrl(array('scope' => 'email,publish_stream,user_status',
'canvas' => 1,
'fbconnect' => 0,
'redirect_uri' => 'http://gno.....ment/index.php'));
}
..... .....
<?php if ($user): ?>
<h3>You</h3>
<img src="https://graph.facebook.com/<?php echo $user; ?>/picture">
<h3>Your User Object (/me)</h3>
<pre><?php print_r($user_profile); ?></pre>
<?php else: ?>
<strong><em>You are not Connected.</em></strong>
<?php endif ?>
<?php if ($user): ?>
<a href="<?php echo $logoutUrl; ?>">Logout of FB</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 ?>
似乎 if ($_GET['logout'] == "yes")
可能是我的答案,但我无法让它工作。我不知道 logout
是从哪里得到的,也不知道它是在哪里定义的?
这似乎是一个常见问题,但我无法弄清楚。非常感谢您的帮助。
最佳答案
用 PHP SDK 做起来真的很容易,文档真的很糟糕。您不需要重定向到 Facebook。您只需清除 Facebook 类设置的 session ,在 Facebook 基类中有一个名为 destroySession() 的函数。在这里,我正在做这件事。
require_once('libs/facebook.php');
$facebook = new Facebook(array(
'appId' => 'xxxxxx',
'secret' => 'xxxxxx'
));
$facebook->destroySession();
$facebook->getLogoutUrl() 将用户从 Facebook 中注销。
关于php - Facebook PHP SDK - 无法正确注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10366366/