Facebook邀请朋友的请求javascript

问题描述:

我有一个问题,通过Facebook上的Facebook应用程序邀请朋友的请求。 我的代码是: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上,我的网站是用PHP制作的。 因为我在虚拟主机上,所以无法向您显示该应用。

+0

我认为这是铬的问题!我如何解决这个问题? – 2012-08-02 10:12:52

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

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