Click event capture for Like button

I'm trying to sign up for a Like button. Here is the code I have:

<body> <!-- Facebook Like Button with your App ID --> <div id="fb-root"></div> <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=349467237487892"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); FB.Event.subscribe('edge.create', function(response) { alert('You liked the URL: ' + response); } ); 

The β€œLike” button appears and works fine, but I don’t get a warning when pressed. Does anyone see a problem?

Thank you for your help.

+4
source share
2 answers

You need to attach the event after the JS SDK had the ability to load. Use fbAsyncInit for this.

 window.fbAsyncInit = function() { FB.Event.subscribe('edge.create', function(response) { alert('You liked the URL: ' + response); }); }; 
+5
source

As far as I can tell by the api, you need to subscribe to the edge.create example - an example from the api documentation.

 FB.Event.subscribe('edge.create', function(response) { alert('You liked the URL: ' + response); } ); 

You can learn more about subscribing to FB here .

+3
source

Source: https://habr.com/ru/post/1391365/


All Articles