我一直在尋找解決這個問題的小時數,但找不到適合我的解決方案。當我在我的網站上點擊「註銷」時,用戶信息仍然可見,並且註銷按鈕仍然顯示。下面是代碼:Facebook的PHP SDK - 將不會正常註銷
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
從哪裏得到或從哪裏定義?
這似乎是一個常見問題,但我不明白。我真的很感謝一些幫助。
謝謝!這應該是被接受的答案。 – celwell 2014-03-21 00:35:39
謝謝!直到你指出它之前,我都不知道它會將我從Facebook註銷。 – Gavin 2014-03-29 11:36:03