0

我使用 facebook javascript sdk 让用户登录,然后使用 php sdk 进行其他进程。这是我的示例代码:

<?php
require_once('AppInfo.php');
require 'src/facebook.php';
$facebook = new Facebook(array(
'appId'  => '*****',
'secret' => '*****',
));
// See if there is a user from a cookie
$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) {
// If the call fails we check if we still have a user. The user will be
// cleared if the error is because of an invalid accesstoken
if (!$facebook->getUser()) {
  header('Location: '. AppInfo::getUrl($_SERVER['REQUEST_URI']));
  exit();
}
}
}
?>
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>Facebook App</title>
<h1>Facebook App</h1>
</head>
<body>
<div id="fb-root"></div>
<script type="text/javascript">               
  window.fbAsyncInit = function() {
    FB.init({
      appId: '<?php echo $facebook->getAppID() ?>', 
      cookie: true, 
      xfbml: true,
      status: true,
      channelUrl : '//<?php echo $_SERVER["HTTP_HOST"]; ?>/fb/channel.html'
    });

    FB.Event.subscribe('auth.login', function(response) {
      window.location.reload();
    });
      FB.Canvas.setAutoGrow();
  };
      // Load the SDK Asynchronously
  (function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/all.js";
    fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));

</script>
 <?php if (isset($basic)) { ?>
 <h1>Hi</h1>

  <div>
    <h1>Welcome Hero</h1>
    <p class="tagline">
      This is your app
    </p>
  </div>
<?php } else { ?>
<div>
    <h1>Welcome Villian</h1>
    <div class="fb-login-button" data-scope="user_likes,user_photos,publish_stream"></div>
  </div>
  <?php echo $user_profile[id]; 
 echo "hhhh";} ?>
 </body>
    </html> 

问题是我总是看到 Else 部分在运行。即使在用户登录后,它也会显示 else 部分。有人可以帮帮我吗

4

1 回答 1

0

这是 php sdk 中的问题。使用 js sdk 和 phpsdk

于 2012-10-21T17:45:39.843 回答