簡體   English   中英

Facebook Javascript SDK響應回調未觸發

[英]Facebook Javascript SDK response callback not firing

我正在使用Facebook Javascript SDK將其發布到用戶Facebook牆。 他們發布后,我想使用響應回調在頁面上顯示/隱藏一些div。

我的問題是沒有觸發callback(response)函數。 我在控制台中沒有收到任何錯誤,我也嘗試使用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對話框似乎很好。 我可以成功貼到牆上。 對話框關閉后,什么都沒有發生-這是我需要響應回調觸發的時候。

任何幫助將不勝感激。 我花了很長時間試圖找到解決方案。

因此,我將回答我自己的問題:

onclick="shareToWall();return false;"

“返回假”解決了我的問題,回調現在成功觸發。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM