0

我刚刚在这里下载了库 https://github.com/facebook/php-sdk/

以下是我的代码:

require_once "/facebook-platform/clients/php/trunk/facebook.php";

$appapikey = 'secret';
$appsecret = 'secret';

$facebook = new Facebook($appapikey, $appsecret);
$user_id = $facebook->require_login();

echo "<p>Hello, <fb:name uid=\"$user_id\" useyou=\"false\" />!</p>";

但是没有输出,有什么问题吗?谢谢

4

1 回答 1

2

你从哪里得到这个?

$user_id = $facebook->require_login();

显然,您正在关注使用旧SDK的过时文章。您可以按照发布 的链接中的新 SDK示例进行操作:

<?php

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

$facebook = new Facebook(array(
  'appId'  => '191149314281714',
  'secret' => '73b67bf1c825fa47efae70a46c18906b',
));

// 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) {
    echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
    $user = null;
  }
}

?>
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
  <body>
    <?php if ($user) { ?>
      Your user profile is
      <pre>
        <?php print htmlspecialchars(print_r($user_profile, true)) ?>
      </pre>
    <?php } else { ?>
      <fb:login-button></fb:login-button>
    <?php } ?>
    <div id="fb-root"></div>
    <script>
      window.fbAsyncInit = function() {
        FB.init({
          appId: '<?php echo $facebook->getAppID() ?>',
          cookie: true,
          xfbml: true,
          oauth: true
        });
        FB.Event.subscribe('auth.login', function(response) {
          window.location.reload();
        });
        FB.Event.subscribe('auth.logout', function(response) {
          window.location.reload();
        });
      };
      (function() {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol +
          '//connect.facebook.net/en_US/all.js';
        document.getElementById('fb-root').appendChild(e);
      }());
    </script>
  </body>
</html>

此外,您似乎在代码中使用了不推荐使用的 FBML,现在推荐使用 FBML。改用 iframe!

于 2011-05-05T08:17:15.903 回答