Facebook使用javascript api在页面中自动发送帖子

Raj*_*ish 1 facebook facebook-javascript-sdk

如何在Facebook页面发布Feed?我已经完成了我的墙贴,但我不知道如何使用javascript api在页面中发布墙贴.其实,我想要在我的Facebook墙上发帖

我从facebook api找到了代码.请帮忙.

小智 5

试试这个:

<body>
<div id='fb-root'></div>
<script src='http://connect.facebook.net/en_US/all.js'></script>
<p>
    <a href="javascript:;" onclick='postToFeed(); return false;'>Post to Group</a>
</p>
<p id='msg'></p>

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

  function postToFeed() {

    // calling the API ...
      FB.api('/Pageid/feed', 'post', 
              { 
                  // for the newer versions of the Facebook API you need to add the access token
                  access_token: 'page access token'
                  message     : "It's awesome ...",
                  link        : 'Link',
                  picture     : 'Imageurl',
                  name        : 'Featured of the Day',
                  to: 'Pageid',
                  from: 'Pageid',
                  description : 'Your description'
          }, 
          function(response) {

              if (!response || response.error) {
                  alert(JSON.stringify(response.error));
              } else {
                  alert('Post ID: ' + response.id);
              }
          });
  }

</script>
</body>
Run Code Online (Sandbox Code Playgroud)

放入HTML body标签.