没有回应在FaceBook共享 [英] No Response Back On FaceBook Sharing

查看:146
本文介绍了没有回应在FaceBook共享的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我做了以下脚本

 < 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);
}(文档) );

function get_fb_share(){
FB.ui({
method:'feed',
name:'IGUTS Share',
link: <?php echo base_url();?>,
图片:'http://fbrell.com/f8.jpg',
标题:'参考文档',
描述:'对话框提供一个简单,一致的界面,让应用程序与用户进行接口',
消息:'Facebook对话框很简单!'
},function(response){
if(response& amp ;& response.post_id){
alert('Post was published。');
} else {
alert('Post was not published。');
}
});
}



将上面的代码放在标题



之后,我以下列方式调用 get_fb_share()

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

现在我不知道我做错了什么,我可以分享链接,但我不能得到任何FB响应。



有人可以告诉我为什么?

  EDIT 

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

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

我没有得到任何回应。



但是如果我使用这样的常规按钮,即

 < input type =buttononclick =get_fb_share() ;值= 共享/> 

然后我收到回复。但这并不完美。我正在使用Facebook

 < div class =fb-share-button> 

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



请帮助我找到一个解决方案。

解决方案

我在较新的主题中回答了这个问题,但我只是在这里复制我的答案:



Feed对话框不推荐使用,您应该使用共享对话框。这很容易处理:

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

这是我在取消分享时在控制台中获得的:


Object {error_code:4201,error_message:用户取消了Dialog流}


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


[]


是的,这是一个空数组,它将打到发布未发布警报。如果您以 publish_actions 授权用户,则可以使用该帖子ID,您可以在文档中阅读。



这对我有用:

  FB.ui({
method:'share',
href :你的url
},function(response){
if(response.error_code){
console.log(response);
} else {
console。 log('published');
}
});但是,你不应该使用这些回调imho,不允许激励份额,用户应该能够如果他想要更多的分享。


i want to catch the response when a share is made on facebook and on the response an alert will occur.

i made the following script

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

i put the above code on header

then i am calling the get_fb_share() by the following manner

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

Now i dont know what I made wrong, i can share the link, but I can't get any FB response.

Can anybody tell me why??

EDIT

What i found out is that when I am using this div for the sharing i.e.

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

I am not getting any response.

But if I use a normal button like this, i.e.

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

Then I am getting the response. But this is not perfect. I am using the facebook

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

cause it shows the no. of shares as well. Thats why i need the get_fb_share() function be called by the facebook sharing div and not just by any button.

Please help me find a solution.

解决方案

I´ve answered this in a newer thread, but i will just copy my answer here:

The feed dialog is deprecated afaik, you should use the share dialog instead. It´s a lot easier to handle:

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

This is what i get in the console when i cancel the share:

Object {error_code: 4201, error_message: "User canceled the Dialog flow"}

...and this is what i get when i share:

[]

Yes, that´s an empty array, and it will hit the "Post not published" alert. The post id will only be available if you authorize the user with publish_actions, as you can read in the docs.

This worked for me:

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

BUT: You should not use those callbacks imho, incentivizing shares is not allowed and the user should be able to share more often if he wants to.

这篇关于没有回应在FaceBook共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆