0

これは、開始 body タグのすぐ下から始まる私のコードです。

<div id="fb-root"></div>
<script>
alert("made it into the script");
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
  appId      : '360348567392858', // App ID from the App Dashboard
  channelUrl : 'http://chrisvanhorne.com/users/erosas/final/channel.html', // Channel      File for x-domain communication
  status     : true, // check the login status upon init?
  cookie     : true, // set sessions cookies to allow your server to access the session?
  xfbml      : true  // parse XFBML tags on this page?
});

// Additional initialization code such as adding Event Listeners goes here
    FB.getLoginStatus(function(response) {
      if (response.status === 'connected') {
         // User logged into FB and authorized
            testAPI();
            document.getElementById('fb-logout').style.display = 'block';
      } else if (response.status === 'not_authorized') {
        // User logged into FB but not authorized
            login();
      } else {
        // User not logged into FB
            login();
            document.getElementById('fb-logout').style.display = 'block';
      }
     });

};

    function login() {
    FB.login(function(response) {
        if (response.authResponse) {
            // connected
            alert("made it to login");
            testAPI();
        } else {
            // cancelled
        }
    });
}

function testAPI() {
    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function(response) {
        console.log('Good to see you, ' + response.name + '.');
    });
}   

 // Load the SDK's source Asynchronously
 // Note that the debug version is being actively developed and might 
 // contain some type checks that are overly strict. 
 // Please report such bugs using the bugs tool.
 (function(d, debug){
 var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
 if (d.getElementById(id)) {return;}
 js = d.createElement('script'); js.id = id; js.async = true;
 js.src = "//connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js";
 ref.parentNode.insertBefore(js, ref);
 }(document, /*debug*/ false));


</script>

ログイン機能は正常に動作しますが、その後、このスクリプト タグ内の関数を呼び出すことはできません。それだけでなく、奇妙なことに、<script>JavaScript を含む no は、Facebook スクリプト コードの後でまったく機能しません。debug alert() 関数は呼び出されず、呼び出しも行われません (Facebook に伝えることができます)。

私が検討したいくつかの考えられる問題ですが、確信が持てません:

  1. 私はヘッダーとフッターを呼び出すためにphpを使用していますが、このコードはヘッダーにありますが、それが読み込みに影響するかどうかはわかりません
  2. これを介してアクセスするドメインはパスワードで保護されています。つまり、この URL に移動するとウィンドウがポップアップし、ページを表示するにはログインする必要があります。それが Facebook の SDK/サーバーを台無しにするかどうかはよくわかりません。
  3. たぶん、私が見ていないかなり明白な解決策があるかもしれません

私は現在これを理解しようとして夢中になっているので、どんな助けも大歓迎です、ありがとう!

4

1 に答える 1

0

信じられないことですが、コードが init 関数の完了を待っていなかったことと、head に「悪い」javascript タグ (表示されていません) が . ではなく: で終わっていたことが原因の 1 つです。簡単な修正、次回は答えを探すのが難しくなります

于 2012-11-30T00:37:03.143 に答える