【问题标题】:facebook logout not workingfacebook注销不起作用
【发布时间】:2012-03-20 11:23:09
【问题描述】:

我已经下载了最新版本的 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>

【问题讨论】:

    标签: facebook web facebook-php-sdk logout


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:
      1. 将数组('next')放入$logoutUrl
      2. 使用session_destroy();

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

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

      【讨论】:

        猜你喜欢
        • 2012-03-28
        • 1970-01-01
        • 1970-01-01
        • 2015-11-08
        • 2014-04-04
        • 2016-10-28
        • 2016-12-20
        • 2013-03-24
        • 1970-01-01
        相关资源
        最近更新 更多