Facebook Like Button doesn't like my code

I am trying to implement the Facebook Like button on my blog as follows:

$("#fblike").append(" <iframe src='http://www.facebook.com/plugins/like.php?app_id=217624258276389&amp;" + window.location.href + "&amp;send=false&amp;layout=box_count&amp;width=50&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=60' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:50px; height:60px;' allowTransparency='true'></iframe>"); 

And adding this to the <head> my HTML source file:

 <script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script> 

The problem is that when I try to check the Like button, it shows 1 instead of 0, and the second later returns to 0. Nothing has changed in my Facebook profile. What is wrong and how to fix it?

PS: I run this on the localhost server, in my case http://nathan-camposs-macbook-pro.local/~Nathan

+6
source share
3 answers

I think events go something like this:

  • You press the button.
  • Javascript sends a similar request to FB.
  • Facebook is trying to access your page ("localhost").
  • He cannot access it, so the request is rejected.

UPDATE: -

I noticed that your src attribute is starting: 'http://www.facebook.com/plugins/like.php?app_id=217624258276389&amp;" + window.location.href + "&amp;

I think it should be: 'http://www.facebook.com/plugins/like.php?app_id=217624258276389&amp;href=" + window.location.href + "&amp;

pay attention to href=

+1
source

I had problems testing similar on sites using temporary URLs. Facebook doesn't like it when the associated app_id is not associated with the url you like. But I could be wrong. If you temporarily expand the width to more than 50 (for example, 300-350), an error link should appear, which will give you more valuable information ...

0
source

If you use fbml, you will not need the application identifier. Using fbml, you can customize several things. I think you already looked at

http://developers.facebook.com/docs/reference/plugins/like/

You can try the following code

 <head> <script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script> </head> 

Then in the body

 <div id="fb-root"></div> <fb:like href="http://yoururl" send="true" width="450" show_faces="true" font=""> </fb:like> 
0
source

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


All Articles