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 Developer tools/firebug などを開いて、コンソールを表示してみてください。

最後に、ユーザーがアプリを承認するためのコードはありません。ユーザーがアカウントへのアクセス許可を付与していない限り、FB.api('/me') はユーザー アクセス トークンを必要とするため、正しい応答を返しません。

于 2013-07-03T11:47:55.133 に答える