簡體   English   中英

FB.ui沒有回調

[英]No callback with FB.ui

我無法讓Facebook UI回調運行。 我使用了FB開發人員站點中的示例:

https://developers.facebook.com/docs/reference/dialogs/feed/

FB.init({appId: "YOUR_APP_ID", status: true, cookie: true});

function postToFeed() {

    // calling the API ...
    var obj = {
      method: 'feed',
      redirect_uri: 'YOUR URL HERE',
      link: 'https://developers.facebook.com/docs/reference/dialogs/',
      picture: 'http://fbrell.com/f8.jpg',
      name: 'Facebook Dialogs',
      caption: 'Reference Documentation',
      description: 'Using Dialogs to interact with users.'
    };

    function callback(response) {
      document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
    }

    FB.ui(obj, callback);
}

當我在我的網站上運行它時,我得不到回叫https://www.ipassexam.com/page/fb-test

任何見解將不勝感激。

擺脫redirect_uri參數。 這對我來說每次都適用:

FB.ui({
    method: 'feed',  
    link: "http://...",
    name: "Some Title",
    caption: "Some Caption",
    description: "Some Description",
    picture: "http://..."
}, function(response) {
    if (response && response.post_id) {
        alert('Post was published.');
    } else {
        alert('Post was not published.');
    }
});

還要確保控制台中沒有錯誤。 但是我還是沒有看到任何錯誤。

花了2個小時來解決問題和解決方案,提到顯示屬性(在我的情況下彈出)。

function postToFeed() {

// calling the API ...
var obj = {
  method: 'feed',
  **display: 'popup',**
  link: 'https://developers.facebook.com/docs/reference/dialogs/',
  picture: 'http://fbrell.com/f8.jpg',
  name: 'Facebook Dialogs',
  caption: 'Reference Documentation',
  description: 'Using Dialogs to interact with users.'
};

function callback(response) {
  document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
}

FB.ui(obj, callback);

}

提示:如果顯式指定為彈出窗口,則redirect_uri不是必需的。

嘗試通過請求將顯示屬性設置為“彈出”,如下所示:

FB.ui({
    method: 'feed',  
    link: "http://...",
    name: "Some Title",
    caption: "Some Caption",
    description: "Some Description",
    display: "popup",
    picture: "http://..."
}, function(response) {
    if (response && response.post_id) {
        alert('Post was published.');
    } else {
        alert('Post was not published.');
    }
});

當我嘗試使用feed方法發布時,我在FB畫布頁面中遇到了這個問題,我總是得到“未定義”的響應。 我已經嘗試了上述屬性,現在可以正常工作了。

也許你應該嘗試使用匿名函數作為回調 -

FB.ui(obj, function(response) {
  document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
});

嘗試在FB.init之前添加它

window.fbAsyncInit = function() { //put FB.init here }

 (function(d){
   var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
   if (d.getElementById(id)) {return;}
   js = d.createElement('script'); js.id = id; js.async = true;
   js.src = '//connect.facebook.net/en_US/all.js';
   ref.parentNode.insertBefore(js, ref);
 }(document));

這樣它就會變成這樣

window.fbAsyncInit = function() {
 FB.init({appId: "YOUR_APPID", status: true, cookie: true});
};

(function(d){
   var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
   if (d.getElementById(id)) {return;}
   js = d.createElement('script'); js.id = id; js.async = true;
   js.src = '//connect.facebook.net/en_US/all.js';
   ref.parentNode.insertBefore(js, ref);
 }(document));

這可能不是你的情況,但我正在尋找類似行為差不多一周的原因,最后我發現FB.ui試圖創建iframe以顯示在頁面上,因為這是在div下創建這個iframe id = fb-root。 不幸的是,這個div在另一個div中,我自己也看不見了! 所以 - 長話短說 - 檢查你是否有id = fb-root的div以及這個div是否可見

暫無
暫無

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

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