2012-04-04 82 views
3

我嘗試登錄到Facebook的,這裏是我的代碼:的Facebook的Javascript SDK本地主機的錯誤消息

<body> 
<form id="form1" runat="server"> 
    <div id="fb-root"></div> 
    <script>  
     (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_GB/all.js#xfbml=1&appId=221385331301885"; 
      fjs.parentNode.insertBefore(js, fjs); 
    } (document, 'script', 'facebook-jssdk')); 
    </script> 
    <div class="fb-login-button" data-show-faces="false" data-width="300"></div> 
    <script> 
     window.fbAsyncInit = function() { 
      FB.init({ 
       appId: '221385323101885', // App ID 
       status: true, // check login status 
       cookie: true, // enable cookies to allow the server to access the session 
       xfbml: true // parse XFBML 
      }); 

      // Additional initialization code here 
     }; 

     // Load the SDK Asynchronously 
     (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> 
</form> 
</body> 

當我運行此代碼我收到此錯誤信息:

enter image description here

我試着使用https://developers.facebook.com/tools/debug調試窗口中的URL但是它一直告訴我URL不可被分割:/如果您想嘗試調試它,則URL在下面:

https://www.facebook.com/dialog/oauth?api_key=221385331301885&app_id=221385331301885&client_id=221385331301885&display=popup&domain=127.0.0.1&locale=en_GB&origin=1&redirect_uri=https%3A%2F%2Fs-static.ak.fbcdn.net%2Fconnect%2Fxd_proxy.php%23cb%3Df4b3e7f08%26origin%3Dhttp%253A%252F%252F127.0.0.1%253A81%252Ff22a06766%26relation%3Dopener%26transport%3Dpostmessage%26frame%3Df23609e538&response_type=token%2Csigned_request&sdk=joey 

我更改了我的主機文件,爲127.0.0.1 localhost.local添加條目以匹配我的Facbook應用設置。下面是我的主機文件的截圖和我的Facebook應用程序的設置:

Hosts File

Facbook App Settings

正如你所看到的域名是兩個hosts文件和Facebook的應用程序設置相同。關於如何解決這個問題的任何想法?感謝

回答

3

我想我找到了你的問題,但我不知道爲什麼會發生?

我試圖做你所做的事,而是與一個移動Web我有HTTP: // localhost in Website option(and the mobile was empty)。一切正常。

當我從網站改變爲移動網絡我得到了你報告的同樣的錯誤。 你有使用移動選項嗎?

此外,正在加載的FB SDK兩次,不知道爲什麼,第一次用這個來源:

//connect.facebook.net/en_GB/all.js#xfbml=1 &的appid = 221385331301885

然後再以這個來源:

「//connect.facebook.net/en_US/all.js」

有什麼意義?簡單地做這件事有什麼問題:

<div id="fb-root"></div> 
<div class="fb-login-button" data-show-faces="false" data-width="300"></div> 
<script> 
    window.fbAsyncInit = function() { 
     FB.init({ 
     appId: '221385323101885', // App ID 
     status: true, // check login status 
     cookie: true, // enable cookies to allow the server to access the session 
     xfbml: true // parse XFBML 
     }); 

     // Additional initialization code here 
    }; 

    // Load the SDK Asynchronously 
    (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> 

希望它能解決您的問題。

+0

我有問題,我已經添加的http://localhost.local作爲網站的網址,但仍然我得到' GET http://static.ak.facebook.com/connect/xd_arbiter.php?版本= 28 403(禁止)' – 2013-11-21 12:13:03

+0

我已經創建了虛擬主機「localhost.local」並使用了上面的代碼 – 2013-11-21 12:23:18

3

添加在Site URL : http://localhost作品對我來說

0

現在,您必須在Apache的虛擬主機