按下按钮时Facebook出错

时间:2012-07-18 11:06:24

标签: javascript jquery facebook

点击“赞”按钮,我明白这一点。

  

不安全的JavaScript尝试从包含网址http://www.facebook.com/dialog/oauth?api_key=248753205242460&app_id=248753205242460&channel_url=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D9%23cb%3Dfedecb848%26origin%3Dhttp%253A%252F%252Flocalhost%252Ff2ad19772%26domain%3Dlocalhost%26relation%3Dparent.parent&client_id=248753205242460&display=none&domain=localhost&locale=en_US&origin=1&redirect_uri=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D9%23cb%3Df99e53428%26origin%3Dhttp%253A%252F%252Flocalhost%252Ff2ad19772%26domain%3Dlocalhost%26relation%3Dparent%26frame%3Df2c40b1914&response_type=token%2Csigned_request%2Ccode&sdk=joey的网址访问包含网址http://www.facebook.com/plugins/like.php?action=like&api_key=248753205242460&channel_url=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D9%23cb%3Df458cef1c%26origin%3Dhttp%253A%252F%252Flocalhost%252Ff2ad19772%26domain%3Dlocalhost%26relation%3Dparent.parent&colorscheme=light&extended_social_context=false&font=segoe%20ui&href=http%3A%2F%2Fecommercedeveloper.com&layout=standard&locale=en_US&node_type=link&sdk=joey&show_faces=true&width=400#的框架。域,协议和端口必须匹配。   不安全的JavaScript尝试从包含网址https://s-static.ak.facebook.com/connect/xd_arbiter.php?version=9#channel=f2ad19772&origin=http%3A%2F%2Flocalhost&channel_path=%2FDummy%2FFBplugin%2Ffb.php%3Ffb_xd_fragment%23xd_sig%3Dfe951f208%26的网址访问包含网址http://www.facebook.com/plugins/like.php?action=like&api_key=248753205242460&channel_url=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D9%23cb%3Df458cef1c%26origin%3Dhttp%253A%252F%252Flocalhost%252Ff2ad19772%26domain%3Dlocalhost%26relation%3Dparent.parent&colorscheme=light&extended_social_context=false&font=segoe%20ui&href=http%3A%2F%2Fecommercedeveloper.com&layout=standard&locale=en_US&node_type=link&sdk=joey&show_faces=true&width=400#的框架。域,协议和端口必须匹配。

我不知道为什么会收到该错误,可能是因为检查登录的代码被触发了..

这是我的HTML:

<!DOCTYPE html>

                                                             

<body>
  <div id="fb-root"></div>

       <script type="text/javascript">
 $(document).ready(function(){          

          FB.init({
            appId      : '248753205242460', // App ID
            status     : true, // check login status
            cookie     : true, // enable cookies to allow the server to access the session
            xfbml      : true  // parse XFBML
            });   



window.fbAsyncInit = function() {
            console.log('Sdk is loaded');


FB.getLoginStatus(function(response) {
                console.log('GEtting logged in status');

  if (response.status === 'connected') {
    // the user is logged in and has authenticated your
    // app, and response.authResponse supplies
    // the user's ID, a valid access token, a signed
    // request, and the time the access token 
    // and signed request each expire
    var uid = response.authResponse.userID;
    console.log('User is connected');
    var accessToken = response.authResponse.accessToken;
  } else if (response.status === 'not_authorized') {
    // the user is logged in to Facebook, 
    // but has not authenticated your app
     console.log('User not authorized');
  } else {
    // the user isn't logged in to Facebook.
     console.log('User inst logged in');
  }
 });
};



 FB.Event.subscribe('edge.create',
    function(response) {
        console.log('You liked the URL: ' + response.status);
    });

});





       </script>        
    </body>
</html>

2 个答案:

答案 0 :(得分:1)

  

我使用的另一个事件是“getLoginStatus”,它会告诉我用户是否登录到facebook ..

这本身并不是一个“事件” - 它只是一个异步方法,它可以让你获得登录状态。

  

console.log('FB.getLoginStatus:'+ FB.getLoginStatus);

此时你甚至没有调用这个方法 - 你只是说出它的名字。 (我知道,你之前正在调用它 - 但是这个调试输出没有多大意义。)

  

我想触发edge.create

您是如何实现类似按钮的?如果您使用按钮的iframe版本,则会触发此事件。

  

[来自评论]我想我需要拥有自己的应用ID ...这可能是原因吗?这是我的Facebook名称而不是数字

你当然可以。您的用户名以任何方式是应用ID。

答案 1 :(得分:1)

错误消息Unsafe JavaScript attempt to access frame with URLDomains, protocols and ports must match通常意味着您的http协议有问题。 您是否应该使用HTTPS代替普通的HTTP?

当我看到这些错误时,我通常会测试我是否在某个地方错过了https ...

另请参阅您的应用是否在Facebook上的开发人员管理面板中设置了所有安全网址!