Facebook邀请好友请求javascript

Facebook invite friend request javascript

本文关键字:javascript 好友请求 Facebook      更新时间:2023-09-26

我在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用php制作的。我无法向您显示该应用程序,因为我在虚拟主机上。

您没有按照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>

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