Facebook发布到墙上不起作用

时间:2012-01-17 07:42:57

标签: facebook iframe facebook-wall

我正在为我的应用开发facebook post to wall功能。我正在使用Facebook Javascript SDK。但事情是,当我通过点击链接调用postToFeed()函数时,它与iframe完美配合。但是如果我想以其他方式加载它(例如body onload),那么iframe会显示错误“发生错误。请稍后重试”。我已经提供了带有FB.ui的access_token,它消除了会话问题,但是如果没有单击链接仍然无法使其工作。以下是我的代码:

<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 个答案:

答案 0 :(得分: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);