FB.ui没有回调

时间:2012-12-30 22:03:05

标签: javascript facebook facebook-javascript-sdk fb.ui

我无法让Facebook UI回调运行。我使用了FB dev网站上的例子:

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

任何见解都将受到赞赏。

6 个答案:

答案 0 :(得分:4)

摆脱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.');
    }
});

还要确保控制台中没有错误。但我还是没有看到任何错误。

答案 1 :(得分:2)

花了2个小时来解决问题,解决方法是,提一下显示属性(在我的情况下是popup)。

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不是必需的。

答案 2 :(得分:1)

尝试使用" popup"设置显示属性请求如下:

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.');
    }
});

我在FB画布页面中遇到过这个问题,当我尝试使用feed方法发布时,我总是得到" undefined"响应。我已经尝试了上面的属性,现在它正在运行。

答案 3 :(得分:0)

也许你应该尝试使用匿名函数作为回调 -

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

答案 4 :(得分:0)

尝试在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));

答案 5 :(得分:0)

这可能不是您的情况,但是我一直在寻找类似行为的原因,将近一个星期,最后我发现FB.ui试图创建要在页面上显示的iframe,并且为此创建了div下ID为fb-root的iframe。 不幸的是,这个div位于另一个我自己看不见的div内! 所以-简而言之-检查您的div是否具有id = fb-root,并且该div是否可见