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.');
}
});
}
</script>
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 don't 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">
Because it shows the no. of shares as well. That's why I need the get_fb_share() function be called by the Facebook sharing div and not just by any button.