使用FB.api在Facebook上发布消息

Post a message in Facebook with FB.api

本文关键字:布消息 消息 FB api Facebook 使用      更新时间:2023-09-26

我试着用FB.api在墙上发布消息。但没有得到任何回应。你能帮我吗?请检查一下我的代码。

function shareWithFacebook(content) {
    FB.api('/me/feed', 'post', {
        message: content
    }, function (response) {        
        if (!response || response.error) {            
            alert('Error : ' + response.error);
        } else {
            alert('Post ID: ' + response.id);            
        }
    });
    return false;
}

试试这个例子

<script>
var publish = {
  method: 'feed',
  message: 'getting educated about Facebook Connect',
  name: 'Connect',
  caption: 'The Facebook Connect JavaScript SDK',
  description: (
      'A small JavaScript library that allows you to harness ' +
      'the power of Facebook, bringing the user''s identity, ' +
      'social graph and distribution power to your site.'
  ),
  link: 'http://www.fbrell.com/',
  picture: 'http://www.fbrell.com/public/f8.jpg',
  actions: [
    { name: 'fbrell', link: 'http://www.fbrell.com/' }
  ],
  user_message_prompt: 'Share your thoughts about RELL'
};
FB.ui(publish, Log.info.bind('feed callback'));
</script>

您的代码没有任何问题:

FB.api('/me/feed', 'post',
        { message: content },
        function(response) {        
           if (!response || response.error) {            
               alert('Error : ' + response.error);
           } else {
               alert('Post ID: ' + response.id);            
           }
        }
);

只需确保您已通过身份验证,并正确调用您的函数shareWithFacebook即可。