2012-11-12 24 views
1

第一:我不是英語,我的英語不是很好,然後抱歉。 我的FB應用程序出現了一些問題。Facebook的方法:飼料 - JavaScript的 - 身體OnLoad

這是代碼:

//My Script 
<script src="http://connect.facebook.net/en_US/all.js"></script> 
<p><a onload="postToFeed(); return false;"> </a></p> 

<p id="msg"></p> 

<script> 
    FB.init({appId: "********", status: true, cookie: true}); 

    function postToFeed() { 

    // calling the API ... 
    var obj = { 
     method: "feed", 
     link: "http://apps.facebook.com/bachflower/", 
     picture: "http://glacial-hollows-5787.herokuapp.com/images/37p.png", 
     name: "Wild Rose - Rosa Canina", 
     caption: " ", 
     description: "Dona: Decisione, motivazione, accettazione con gioia del quotidiano. Chi ne ha bisogno tende a pensare: Non vale la pena… meglio rinunciare. Non serve a nulla… - App by medicinanaturale.pro" 
    }; 

    function callback(response) { 

    } 

    FB.ui(obj, callback); 
    } 

</script> 

//This is my body OnLoad 
<body text="#000000" onLoad="postToFeed();" > 

的問題是: 有些人可以看到並在他們的牆上正確共享postToFeed通知。 有些人看不到有關postToFeed的任何信息。 爲什麼?

任何人都可以幫到我嗎?

比你多, 安德烈

回答

0

的postToFeed()函數FB之前可能被稱爲加載和初始化。 使用異步加載,這樣的:

<div id="fb-root"></div> 
<script> 
    window.fbAsyncInit = function() { 
    // init the FB JS SDK 
     FB.init({ 
      appId  : 'YOUR_APP_ID', // App ID from the App Dashboard 
      channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File for x-domain communication 
      status  : true, // check the login status upon init? 
      cookie  : true, // set sessions cookies to allow your server to access the session? 
      xfbml  : true // parse XFBML tags on this page? 
     }); 

     postToFeed(); 

    }; 

    // Load the SDK's source Asynchronously 
    (function(d, debug){ 
     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" + (debug ? "/debug" : "") + ".js"; 
     ref.parentNode.insertBefore(js, ref); 
    }(document, /*debug*/ false)); 
</script> 

在這裏看到:http://developers.facebook.com/docs/reference/javascript/