【问题标题】:Facebook invite friend request javascriptFacebook 邀请好友请求 javascript
【发布时间】:2012-08-02 09:28:45
【问题描述】:

我在 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 制作的。 由于我在虚拟主机上,因此无法向您展示该应用。

【问题讨论】:

  • 我认为是chrome的问题!我该如何解决?

标签: javascript facebook facebook-javascript-sdk


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-27
    • 1970-01-01
    相关资源
    最近更新 更多