Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
42
rated 0 times [  45] [ 3]  / answers: 1 / hits: 40005  / 10 Years ago, wed, april 16, 2014, 12:00:00

I have a webpage where I have placed a Facebook like & share button and corresponding javascript callback functions are also present.



Now the problem is, the javascript callback fires only when the user 'likes' and doesn't seem to fire when the 'share' button is pressed.



Its like I need to award the user everytime he/she shares the link. Whereas with 'like', a user can only like a link once (not considering unlike/re-like).



I know that the Share button is deprecated. But facebook now provides a share button with a like button. Source : https://developers.facebook.com/docs/plugins/like-button/



Is there a way to fire this callback method from this share button?



Here's my code :



Code at the beginning of the BODY tag in my HTML :-



<div id=fb-root></div>

<script>
window.fbAsyncInit = function() {
FB.init({
appId: ' My App ID ',
status: true,
cookie: true,
xfbml: true,
oauth: true
});
FB.Event.subscribe('edge.create', function(response) {
alert('You liked the URL: ' + response);

});
};
(function(d) {
var js, id = 'facebook-jssdk';
if (d.getElementById(id)) {
return;
}
js = d.createElement('script');
js.id = id;
js.async = true;
js.src = //connect.facebook.net/en_US/all.js;
d.getElementsByTagName('head')[0].appendChild(js);
}(document));

</script>


Code to display the Like & Share Buttons:-



<div class=fb-like data-href= My URL  data-layout=button_count data-action=like data-show-faces=false data-share=true></div>

More From » facebook

 Answers
41

You cannot get the share callback using this like button. You can instead create a share button of yours and invoke the Feed Dialog on its click-



FB.ui(
{
method: 'feed',
name: 'Facebook Dialogs',
link: 'https://developers.facebook.com/docs/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
caption: 'Reference Documentation',
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);

[#71429] Tuesday, April 15, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shamya

Total Points: 38
Total Questions: 101
Total Answers: 96

Location: Thailand
Member since Thu, Apr 22, 2021
3 Years ago
;