Facebook邀请朋友请求javascript

时间:2012-08-02 09:28:45

标签: javascript facebook facebook-javascript-sdk

我在Facebook应用程序上通过javascript发出邀请朋友请求时遇到问题。 我的代码是:

<div id="fb-root"></div>
    <script>
                $(function() {
        FB.init({
            appId      : '<?php echo APP_ID;?>', // App ID
            status     : true, // check login status
            cookie     : true, // enable cookies to allow the server to access the session
            xfbml      : true,  // parse XFBML
            frictionlessRequests : true,
        });
        FB.Canvas.setAutoGrow();
                    function sendRequestViaMultiFriendSelector(){
                        FB.ui({method: 'apprequests',
                            message: 'My Great Request DONALD'
                        });
                    }
                });
    </script>

当然,我通过以下方式导入了js sdk:

<script src="http://connect.facebook.net/en_US/all.js"></script>

我将按钮绑定以邀请朋友:

$('.step2').children('.tasto').click(function(){
    //sendRequestViaMultiFriendSelector();
    console.log("Gooby pls");
});

在我的页面中,控制台出现此错误:

Unsafe JavaScript attempt to access frame with URL http://apps.facebook.com/termapp/ from frame with URL https://s-static.ak.facebook.com/connect/xd_arbiter.php?version=9#channel=f25e11b77&origin=http%3A%2F%2Fwww.termapp.test&channel_path=%2F%3Ffb_xd_fragment%23xd_sig%3Df3245a897%26. Domains, protocols and ports must match.

自然按钮不起作用。

我在Chrome上,我的网站是用Zend制作的。 因为我在虚拟主机上,所以我无法向您展示应用程序。

1 个答案:

答案 0 :(得分:0)

您没有像FB推荐的那样加载all.js文件。看一下这里的文档:

https://developers.facebook.com/docs/reference/javascript/

该页面建议异步加载API:

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'YOUR_APP_ID', // App ID
      channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
      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>

有关频道文件等的详细信息,请参阅文档。

相关问题