0

我正在使用 Facebook Javascript SDK 发布到用户 Facebook 墙。一旦他们发布了我想使用响应回调在页面上显示/隐藏一些 div。

我的问题是回调(响应)函数没有触发。我在控制台中没有任何错误,我也尝试使用 Facebook 的调试来调试我的代码。仍然没有喜悦。这是我第一次使用 Facebook Javascript SDK,所以(希望)我只是错过了一些非常简单的东西。

这是我的代码:

我在页面顶部有这个,就在结束 body 标记之后:

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    // init the FB JS SDK
    FB.init({
      appId      : '647542748631249', // App ID from the App Dashboard
      status     : true, // check the login status upon init?
      xfbml      : true  // parse XFBML tags on this page?
    });   

  };

  // Load the SDK asynchronously
    (function(){
       // If we've already installed the SDK, we're done
       if (document.getElementById('facebook-jssdk')) {return;}

       // Get the first script element, which we'll use to find the parent node
       var firstScriptElement = document.getElementsByTagName('script')[0];

       // Create a new script element and set its id
       var facebookJS = document.createElement('script'); 
       facebookJS.id = 'facebook-jssdk';

       // Set the new script's source to the source of the Facebook JS SDK
       facebookJS.src = '//connect.facebook.net/en_US/all.js';

       // Insert the Facebook JS SDK into the DOM
       firstScriptElement.parentNode.insertBefore(facebookJS, firstScriptElement);
     }());
</script>

我的页面底部有这段代码:

    function shareToWall(){

    var obj =
      {
       method: 'feed',
       name: 'The 1001 Albums Quiz',
       caption: '',
       description: (
          'I scored '+numberOfChecked+' out of '+totalCheckboxes+' in the Great 1,001 Albums Quiz. Can you do better?'
       ),
       link: 'https://apps.facebook.com/albumsquiz/',
       picture: 'https://mydomain.co.uk/wp-content/themes/facebook1001/images/testimg.png'
      };
      function callback(response) {
        if(response && response.post_id) {
          console.log('Post was published.');
          jQuery('#quiz').hide();
          jQuery('#score').append(numberOfChecked);
          jQuery('#total').append(totalCheckboxes);
          jQuery('#results').show();
        } else {
            console.log('post not published');
        }
      } 
    FB.ui(obj, callback);
  }

单击页面上的按钮会调用函数“shareToWall”。Facebook 对话框显示得很好。我可以成功发布到我的墙上。对话框关闭后没有任何反应 - 这是我需要触发响应回调的时候。

任何帮助将不胜感激。我花了很长时间试图找到解决方案。

4

1 回答 1

0

所以我会回答我自己的问题:

onclick="shareToWall();return false;"

'return false' 解决了我的问题,回调现在成功触发。

于 2013-11-14T19:01:17.867 回答