0

我只想制作一个在我登录时发布的脚本。我找到了这段代码

var body = 'i13 App - Post test';
    FB.api('/me/feed', 'post', { message: body }, function(response) {
        if (!response || response.error) {
        alert('Error occured');
         }else {
        alert('Post ID: ' + response.id);
        }
    });

它适用于 Facebook javascipt 测试控制台,但是当我输入脚本时,我永远无法发布并收到警报('发生错误),

谢谢你的帮助,

4

1 回答 1

0

您是否正确设置了页面代码?确保您在页面中有以下代码

<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
      status     : true,                                 // Check Facebook Login status
      xfbml      : true                                  // Look for social plugins on the page
    });

    // Additional initialization code such as adding Event Listeners goes here
  };

  // Load the SDK asynchronously
  (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/en_US/all.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));
</script>

https://developers.facebook.com/docs/reference/javascript/

用户登录成功后,您可以有一个按钮触发以下代码“

var body = 'Reading JS SDK documentation';
FB.api('/me/feed', 'post', { message: body }, function(response) {
  if (!response || response.error) {
    alert('Error occured');
  } else {
    alert('Post ID: ' + response.id);
  }
});

https://developers.facebook.com/docs/reference/javascript/FB.api/

于 2013-10-22T21:40:24.110 回答