FB.ui的feed没有回调

4

我无法从我的Facebook FB.UI()方法中获得任何反馈。实际上,我已经成功将帖子发布到了我的个人主页,但回调数据要么不存在,要么为空。我相信我使用的是正确的方法,代码如下:

                    FB.ui({
                       method: 'feed',
                        name: 'asd',
                        link: 'asd',
                        picture: '',
                        description: 'asd'
                    }, function(response) {
                        console.log(response);
                            if(response.post_id) {
                               $.post("ajax/wall.php",{wall : 1});
                            } else {

                            }
                        }
                    );
6个回答

3

我不确定这个问题是怎样解决的,但它已经解决了 :)

我清除了缓存并将代码更改为以下内容,然后它就起作用了(不过我认为代码的更改实际上没有影响):

FB.ui({method: 'feed',name: '',link: '',picture: '',description: 'asd'}, function(data) {
    console.log(response);
    if(data && data.post_id) {
        $.post("ajax/wall.php",{wall : 1});
    } else {
        alert("not sent");  
    }
 });

2

移除redirect_uri项,回调将被触发。

我之前也遇到了同样的问题,后来意识到移除redirect_uri解决了它。


3
他的样本中不包含 redirect_uri。 - Himmators
“中立投票” - 我也遇到了这个问题,而且我也没有使用redirect_uri。当然,这并不意味着这不能解决某些人的问题,只是对于我(和OP)来说不行。因此,不会点赞也不会点踩...只是中立投票并附上评论。 :) (虽然我很想点踩!也许你可以更新你的答案,使其更相关一些?) - rinogo

2

我有同样的问题,但从未能够得到Facebook回调函数的响应。我在函数中没有看到任何console.log或任何警报。

我的解决方案是在FB.ui的redirect_uri中放置一个URL,该URL指向一个具有self.close(或window.close)的HTML页面。用户输入后,FB.ui弹出窗口会重定向到该页面并立即关闭。记得更改你的FB应用程序的站点URL设置,使其与文件所在的域匹配。

下面是我的代码,绑定在我的表单提交操作上。function(response)回调仍然存在,但未使用。如果有人看到语法错误,请在评论中指出。

    FB.ui ({
        method: 'feed',
        name: '',
        link: '',
        picture: '',
        caption: '',
        description: '',
        actions: {name:'',link:''},
        redirect_uri: 'http://.../self.close.html'
        },
        function(response) {
            console.log(response);
            if (response && response.post_id) {
                alert('yes');
                self.close();
            } else {
                alert('else yes');
            }
        });

在self.close.html文件中的代码行:

<script type="text/javascript">self.close();</script>

2

针对后来遇到此问题的任何人,我也遇到了完全相同的问题,并通过以下方式解决:

<div class="post-view-backdrop hide" id='post-view-backdrop'>
    <div id="fb-root"></div>

成为

<div class="post-view-backdrop hide" id='post-view-backdrop'></div>
<div id="fb-root"></div>

post-view-backdrop div本来不应该包含fb-root,我只是错过了一个闭合标签。

问题在于我的fb-root周围的HTML格式不正确。我只是凭直觉发现了这个问题,这绝对是使用HTML验证器的理由。


1
设置重定向URI会禁用回调。

1

对于任何在Phonegap上处理此问题的人——问题出在fb connect插件上。它根本不会触发回调函数。

这是FacebookConnectPlugin.m中的代码片段:

////////////////////////////////////////////////////////////////////
// FBDialogDelegate

/**
 * Called when the dialog succeeds and is about to be dismissed.
 */
- (void)dialogDidComplete:(FBDialog *)dialog
{
    // TODO
}

/**
 * Called when the dialog succeeds with a returning url.
 */
- (void)dialogCompleteWithUrl:(NSURL *)url
{
    // TODO 
}

/**
 * Called when the dialog get canceled by the user.
 */
- (void)dialogDidNotCompleteWithUrl:(NSURL *)url
{
    // TODO 
}

/**
 * Called when the dialog is cancelled and is about to be dismissed.
 */
- (void)dialogDidNotComplete:(FBDialog *)dialog
{
    // TODO 
}

我不是Objective C程序员,所以我不会尝试解决这个问题,可能得等插件完成...


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接