2012-08-02 120 views
0

我有一個問題,通過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

回答

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> 

請參閱有關頻道文件的詳細信息,文檔等