【问题标题】:No Response Back On FaceBook Sharing?Facebook 分享没有回复?
【发布时间】:2015-03-23 10:07:01
【问题描述】:

我想在 facebook 上进行分享时捕捉响应,并且在响应中会出现警报。 我做了以下脚本 注意:这个问题已经问过了,但还没有回答。 Click here

    <div id="fb-root"></div>
    <script type="text/javascript">
window.fbAsyncInit = function() 
                         {
                                FB.init({
                                appId:'<?php echo $this->config->item('appID'); ?>', cookie:true,
                                status:true, xfbml:true,oauth : 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));

function get_fb_share()
{
    FB.ui(
   {
     method: 'feed',
     name: 'IGUTS Share',
     link: "<?php echo base_url();?>",
     picture: 'http://fbrell.com/f8.jpg',
     caption: 'Reference Documentation',
     description: 'Dialogs provide a simple, consistent interface for applications to interface with users.',
     message: 'Facebook Dialogs are easy!'
   },
   function(response) {
     if (response && response.post_id) {
       alert('Post was published.');
     } else {
       alert('Post was not published.');
     }
   }
 );
}
</script>

我把上面的代码放在标题上

然后我通过以下方式调用 get_fb_share()

<div class="fb-share-button" data-href="<?php echo base_url();?>" 
                                                 data-width="50" data-type="button_count"
                                                 onclick="get_fb_share();"></div>

现在我不知道我做错了什么,我可以分享链接,但我无法得到任何 FB 回复。

谁能告诉我为什么?

EDIT

我发现当我使用这个 div 进行共享时,即

<div class="fb-share-button" data-href="<?php echo base_url();?>" 
                                                     data-width="50" data-type="button_count"
                                                     onclick="get_fb_share();"></div>

我没有得到任何回应。

但如果我使用这样的普通按钮,即

<input type="button" onclick="get_fb_share();" value="share"/>

然后我得到了回应。但这并不完美。我正在使用脸书

<div class="fb-share-button">

因为它显示没有。的股份也是如此。这就是为什么我需要由 facebook 共享 div 而不仅仅是任何按钮调用 get_fb_share() 函数。

请帮我找到解决办法。

【问题讨论】:

    标签: jquery facebook fbml fbconnect


    【解决方案1】:

    Feed 对话框已弃用 afaik,您应该改用 share dialog。它更容易处理,只需从 URL 中获取 Open Graph 标签:

    FB.ui({
        method: 'share',
        href: your-url
    }, function (response) {
        console.log(response);
    });
    

    这是我取消共享时在控制台中看到的内容:

    Object {error_code: 4201, error_message: "用户取消了对话流程"}

    ...这就是我分享时得到的:

    []

    是的,这是一个空数组,它会触发“帖子未发布”警报。帖子 ID 仅在您使用 publish_actions 授权用户时可用,您可以在文档中阅读。

    这对我有用:

    FB.ui({
        method: 'share',
        href: your-url
    }, function (response) {
        if (response.error_code) {
            console.log(response);
        } else {
            console.log('published');
        }
    });
    

    但是:恕我直言,您不应该使用这些回调,不允许激励分享,如果用户愿意,他应该能够更频繁地分享。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多