2012-01-17 105 views
0

我正在爲我的應用開發Facebook發佈到牆功能。我正在使用Facebook Javascript SDK。但是,當我通過單擊鏈接調用postToFeed()函數時,它可以與iframe完美協作。但是,如果我想以某種其他方式加載(例如body onload),則iframe會顯示錯誤「發生錯誤,請稍後再試」。我已經提供了帶有FB.ui的access_token,它可以消除會話問題,但是如果不點擊鏈接,仍然無法工作。以下是我的代碼:Facebook發佈到牆不工作

<div id='fb-root'></div> 
    <script src='http://connect.facebook.net/en_US/all.js'></script> 
    <p><a onclick='postToFeed(); return false;'>Post to Feed</a></p> 
    <p id='msg'></p> 
    <?php 
    $token_url = "https://graph.facebook.com/oauth/access_token?client_id=MY_CLIENT_ID&client_secret=MY_CLIENT_SECRET&grant_type=client_credentials&redirect_uri=MY_REDIRECT_URI"; 
    $token = file_get_contents($token_url); 

     ?> 

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

    function postToFeed() { 

    // calling the API ... 
    var obj = { 
     method: 'stream.publish', 
     display: 'iframe', 
     access_token: '<?php echo $token;?>', 
     link: 'https://developers.facebook.com/docs/reference/dialogs/', 
     picture: 'http://fbrell.com/f8.jpg', 
     name: 'Facebook Dialogs', 
     caption: 'Reference Documentation', 
     description: 'Using Dialogs to interact with users.' 
    }; 

    function callback(response) { 
     document.getElementById('msg').innerHTML = "Post ID: " + response['post_id']; 
    } 

    FB.ui(obj, callback); 
    } 

</script> 

我的應用程序現在處於沙盒模式。但我想這不是問題。請幫助我。謝謝

回答

1

您的方法似乎不正確。您可能不會使用Facebook上的最新示例。參見:https://developers.facebook.com/docs/reference/dialogs/feed/

// calling the API ... 
var obj = { 
    method: 'feed', 
    link: 'https://developers.facebook.com/docs/reference/dialogs/', 
    picture: 'http://fbrell.com/f8.jpg', 
    name: 'Facebook Dialogs', 
    caption: 'Reference Documentation', 
    description: 'Using Dialogs to interact with users.' 
}; 

function callback(response) { 
    if (response && response.post_id) { 
    document.getElementById('msg').innerHTML = "Post ID: " + response.post_id; 
    } else { 
    alert('Post was not published.'); 
    }  
} 

FB.ui(obj, callback); 
+0

感謝您的回覆。我已經整理出來了...... :) – 2012-02-14 08:05:14

+0

請問你能解決這個問題嗎? – DMCS 2012-02-14 14:15:17

+0

從哪裏我可以關閉這? – 2012-02-20 09:40:09