ddacot
ddacot

Reputation: 1210

Facebook Like button

i'm trying to integrate facebook like button with every post that i read from db.

I got the code from https://developers.facebook.com/docs/reference/plugins/like/. after i put this script in header

<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";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

i've put this code where i need then edited the link

<div class="fb-like" data-href="http://localhost/post.php?id=<?php echo $_GET['id']; ?>" data-send="false" data-width="450" data-show-faces="true"></div>

now it looks ok. (https://i.sstatic.net/Swel4.png). So i hit the like button (https://i.sstatic.net/aLwyh.png) but after refresh it disappears (https://i.sstatic.net/pipGG.png). My question is, what i'm doing wrong and what should i do in order to get those likes stored? Thanks.

Upvotes: 0

Views: 114

Answers (2)

Dany Caissy
Dany Caissy

Reputation: 3206

If you are developing locally, it is possible that Facebook will not register your like since it can not access the page you are liking. If this is your problem, this is perfectly normal and will resolves itself when you put your site online.

Upvotes: 1

ceejayoz
ceejayoz

Reputation: 179994

You can't use an internal URL like http://localhost/ in a Facebook like. The like won't get stored.

Upvotes: 4

Related Questions