Facebook php sdk - 没有显示信息

时间:2013-03-23 14:33:06

标签: php facebook sdk

我是facebook-login系统的新手。我在http://beta.jokesnfunnypics.com/login中添加了以下代码。我刚刚复制了给出的代码,只是替换了我的应用程序ID和我的应用程序秘密。但获得许可后,页面中不会显示任何信息。请帮我。提前谢谢。

<?php
require 'src/facebook.php';
$facebook = new Facebook(array(
  'appId'  => 'my-app-id-undisclosable',
  'secret' => '-my-app-secret-undisclosable',
));
// Get User ID
$user = $facebook->getUser();
if ($user) {
  try {
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}

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>

    <?php if ($user): ?>
      <h3>You</h3>
      <img src="https://graph.facebook.com/<?php echo $user; ?>/picture">
      <?php echo $user_profile[name]; ?>
    <?php else: ?>
      <strong><em>You are not Connected.</em></strong>
    <?php endif ?>
  </body>
</html>

0 个答案:

没有答案