4

我已經設置了由Jquery觸發的共享彈出窗口。它的工作原理,但我想使用響應值觸發成功的AJAX調用,Facebook只返回一個空數組。爲什麼FB.UI共享響應什麼都不返回?

這裏是JavaScript

 

    $("#fb-request").click(function() { 
     FB.ui({ 
      method: 'share', 
      name: 'Check out website', 
      href: 'URL_TO_SHARE', 
     }, 
     function (response) { 
      if (response && !response.error_code) { 
       console.log(response); // Returns: [] 
      } 
     }); 
    }); 

正因爲如此,我不能讓別人誰的帖子,有人誰使用取消按鈕之間的差異。我在這裏錯過了什麼嗎? 或者有什麼可以在Facebook應用上設置的東西?

感謝,

+1

Tagged:jQuery lol – 2015-09-24 13:32:10

回答

3

documentation

響應數據

參數說明 OBJECT_ID 僅當用戶使用Facebook的登錄到您的應用程序,並授予publish_actions。如果存在,這是發佈的Open Graph故事的ID。

+0

我的疑惑現在已經解決了!這應該被標記爲接受的答案。 – andufo 2014-12-20 02:33:50

+1

好吧,我登錄FB.login的背景,但這並沒有幫助,我仍然得到空的迴應 – 2016-02-01 11:33:40

+1

你應該提供登錄訪問權限,它是這樣的: 'function myFacebookLogin(){ FB。 login(function(){},{scope:'publish_actions'}); }' – 2016-02-01 11:54:46

2

如果用戶取消了對話框中的份額,響應是不確定的,所以:

$("#fb-request").click(function() { 
    FB.ui({ 
     method: 'share', 
     name: 'Check out website', 
     href: 'URL_TO_SHARE', 
    }, 
    function (response) { 
     if (response && !response.error_code) { 
      if (typeof response != 'undefined'){ 
       //shered 
      } 
     } 
    }); 
}); 
+0

此代碼在PC/Android中正常工作,但在iOS上無法使用。 只要用戶沒有登錄到您的應用程序(具有適當的權限),響應的值將始終是一個空數組(不管共享是否發生)。 – 2017-07-02 14:34:10

0

首先檢查,如果你的用戶連接。

FB.getLoginStatus(function(response) { 
if (response.status === 'connected') { 
    FB.ui(
     { 
      method: 'feed', 
      link: 'your_url', 
      mobile_iframe: true 
     }, 
     function(response){ 
     }); 
} 
else { 
    FB.login(function(response){ 
     FB.ui(
     { 
      method: 'feed', 
      link: 'your_url', 
      mobile_iframe: true 
     }, 
     function(response){ 
     }); 
    }); 
} 

});

0

這對我有用。

FB.ui({ 
    method: 'share', 
    display: 'popup', 
    href: url, 
}, function(response){ 
    if (typeof response != 'undefined'){ 
     alert("shared"); 
    }else{ 
     alert("no shared"); 
    } 
});