facebook注销无法正常工作

时间:2012-03-20 11:23:10

标签: facebook web facebook-php-sdk logout

我已下载最新版本的facebook php sdk。我可以在我的网站上使用fb登录。但注销无效。该脚本会记住用户数据。如何纠正这个问题?以下是我正在使用的代码。

<?php
require '../src/facebook.php';

$facebook = new Facebook(array(
 'appId'  => 'xxxxxxxxx',
 'secret' => 'xxxxxxxxxxxxxxxxxx',
));

// Get User ID
$user = $facebook->getUser();

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 ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
}


?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>php-sdk</title>
<style>
  body {
    font-family: 'Lucida Grande', Verdana, Arial, sans-serif;
  }
  h1 a {
    text-decoration: none;
    color: #3b5998;
  }
  h1 a:hover {
    text-decoration: underline;
  }
 </style>
 </head>
 <body>
 <h1>php-sdk</h1>

 <?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 ?>

<h3>PHP Session</h3>
<pre><?php print_r($_SESSION); ?></pre>

<?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 ?>


</body>
</html>

2 个答案:

答案 0 :(得分:0)

从您的Facebook帐户中删除该应用,然后重试。 这解决了我的问题。

答案 1 :(得分:0)

  1. 将数组('next')放到$logoutUrl
  2. 使用session_destroy();

    $logoutUrl = $facebook->getLogoutUrl(array('next' => 'url_you_are_redirecting_user_to')); session_destroy();

  3. 请注意,重定向链接应与所有Facebook应用程序位于同一域范围内。否则,您将被重定向到Facebook主页。

相关问题