Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook like button showing error when clicked

I want to show facebook like button. When a user clicks on the button it should make a callback after a user successfully likes that 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 is not working. When you click on the like button it shows an error. Can someone please tell me how to solve this issue?

like image 470
NewUser Avatar asked Oct 19 '22 07:10

NewUser


2 Answers

It could be worth changing the js.src line. To me I see it as though this line is looking for a local file.

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

I previously used the following line, but I'm not sure of the difference to be truthful:

 js.src = "https://connect.facebook.net/en_US/sdk.js#xfbml=1"
like image 146
LiamH Avatar answered Oct 21 '22 01:10

LiamH


You can get the code to like a Facebook page built for you directly by Facebook at this site --> https://developers.facebook.com/docs/plugins/like-button

That way you avoid deprecation issues, etc.

Just go there, enter the pertinent info, grab the code they spit out and place it on your site.

good luck!

like image 33
Jaxian Avatar answered Oct 21 '22 03:10

Jaxian