Facebook as a button showing an error when clicked

I want to show the facebook button as a button. When the user clicks the button, he should make a callback after the user successfully likes this page. Here is my code:

<div class="fb-like" data-href="https://developers.facebook.com/docs/plugins/" data-width="200" data-layout="box_count" data-action="like" data-size="large" data-show-faces="false" data-share="false"></div> <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/sdk.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); </script> <script> window.fbAsyncInit = function() { FB.init({ appId : '510679165797120', xfbml : true, version : 'v2.6' }); FB.Event.subscribe('edge.create', function(response) { console.log('hello'); }); }; </script> 

But it does not work. When you click on the button, it shows an error. Can someone please tell me how to solve this problem?

+5
source share
3 answers

It might be worth changing the js.src line. It seems to me that this line is looking for a local file.

 js.src = "https://connect.facebook.net/en_US/sdk.js"; 

I used the following line earlier, but I'm not sure if the difference will be true:

  js.src = "https://connect.facebook.net/en_US/sdk.js#xfbml=1" 
+1
source

You can get a code similar to the Facebook page created directly for you by Facebook on this site β†’ https://developers.facebook.com/docs/plugins/like-button

This way you avoid obsolescence issues, etc.

Just go there, enter the relevant information, take the code that they spit out, and put it on your website.

Good luck

+1
source

enter image description here

also to work, your callback function should be on top as below

 <script> window.fbAsyncInit = function() { FB.init({ appId : '#############', xfbml : true, version : 'v2.6' }); FB.Event.subscribe('edge.create', function(response) { console.log('hello'); }); }; (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/sdk.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); </script> 
+1
source

All Articles