0

Facebook ログインを自分の Web サイトに統合しようとしています。現在、ローカル ホストを介して Facebook ログインをテストしています。これは、Facebook JavaScript SDK ガイドの指示に従って生成したコードです。

<html>
<body>
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '*************', // App ID
      channelUrl : 'http://localhost', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });

    FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
    // connected
    testAPI();
  } else if (response.status === 'not_authorized') {
    // not_authorized
    login();
  } else {
    // not_logged_in
    login();
  }
 });
  };

  function login() {
    FB.login(function(response) {
        if (response.authResponse) {
            // connected
            testApi();
        } else {
            // cancelled
            console.log('Login failed!');
        }
    });

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

  (function(d){
     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.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));
</script>
<script src="//connect.facebook.net/en_US/all.js"></script>
</body>
</html>

リソースの読み込みに失敗したと言っています:file://connect.facebook.net/en_US/all.js基本的に GET all.js に失敗しています。どうしたの?

私の Facebook アプリ ダッシュボードにはlocalhost、AppDomain とサイト URL がありますhttp://localhost

4

2 に答える 2

0

次のコードを試してください。

(function(){
var e   = document.createElement('script');
e.type  = 'text/javascript';
e.src   = 'http://connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
于 2013-02-22T07:33:15.727 に答える