2012-04-04 77 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的虚拟主机