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 Note: This question already asked but not answered yet. 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>
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.
The feed dialog is deprecated afaik, you should use the share dialog instead. It´s a lot easier to handle and just takes the Open Graph tags from the URL:
This is what i get in the console when i cancel the share:
...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:
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.