0

我有这段代码,我从 facebook 上的官方教程中获得

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<div id="fb-root">sei qui</div>
<script>
  window.fbAsyncInit = function() {
    // init the FB JS SDK
    FB.init({
      appId      : '173721946132851',                        // App ID from the app dashboard
      channelUrl : '//www.ilmiobloggo.net/LOVECALCULATOR/index.php', // Channel file for x-domain comms
      status     : true,                                 // Check Facebook Login status
      xfbml      : true                                  // Look for social plugins on the page
    });

    // Additional initialization code such as adding Event Listeners goes here
  };

  // 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'));



   FB.api('/me', function(response) {
  alert('Your name is ' + response.name);
});
</script>


</body>
</html>

但是 FB.api 不起作用,我不明白为什么,有人可以帮我。我试图获取我家主机的 Apache 日志错误,但没有。

4

1 回答 1

0

尝试放置

  FB.api('/me', function(response) {
  alert('Your name is ' + response.name);
  });

在说的那一行下

  // Additional initialization code such as adding Event Listeners goes here

但高于

  };

例如

    window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
  appId      : '173721946132851',                        // App ID from the app dashboard
  channelUrl : '//www.ilmiobloggo.net/LOVECALCULATOR/index.php', // Channel file for x-domain comms
  status     : true,                                 // Check Facebook Login status
  xfbml      : true                                  // Look for social plugins on the page
});

// Additional initialization code such as adding Event Listeners goes here
FB.api('/me', function(response) {
alert('Your name is ' + response.name);
});
};

您在创建 FB 之前调用 FB.api。这也会产生 JavaScript 错误,这些错误会在您的浏览器中找到。不在 Apache 日志中。尝试打开 Chrome 开发者工具/firebug 等并查看控制台。

最后一点,您没有任何代码供用户授权您的应用程序。除非用户已授予访问您帐户的权限,否则 FB.api('/me') 不会返回正确的响应,因为它需要用户访问令牌

于 2013-07-03T11:47:55.133 回答