38

It is possible to test "Like" button on localhost?

Dave
  • 11,499
  • 5
  • 34
  • 46
Tomasz Gutkowski
  • 1,388
  • 4
  • 20
  • 28

4 Answers4

28

Not really; facebook has to crawl your site to pull in the title, description, and thumbnail. It can't get to your site if it's on localhost.

Dave
  • 11,499
  • 5
  • 34
  • 46
  • Related to what @M.G.Palmer mentioned, if you can get a public IP address or DNS entry for your local box, and make sure the box is accessible to the outside world, you could use that instead of 'localhost'. – Dave Aug 29 '12 at 12:54
27

Dave's answer is correct, however, I just discovered a workaround: You can make your local machine accessible by using http://localtunnel.me . You'll need to (temporarily) change some URLs used in your app code / html so links point to the temporary domain, but at least facebook can reach your machine.

Seb D.
  • 5,046
  • 1
  • 28
  • 36
Martin T.
  • 3,132
  • 1
  • 30
  • 31
  • localtunnel is really convenient to test sharing meta description, title and image. – svassr Sep 12 '12 at 20:18
  • 1
    Thanks M.G.Palmer, localtunnel.com works like a charm! Here an announcement about localtunnel version 2: http://progrium.com/blog/2012/12/25/localtunnel-v2-available-in-beta/ Github: https://github.com/progrium/localtunnel/blob/master/README.md – Sven Jun 05 '13 at 22:45
  • 3
    New url: localtunnel.me – Dan Ross Oct 12 '14 at 13:56
10

It is possible to perform limited testing on the facebook like button on localhost. It renders properly on my machine. The trick is using a live, non-localhost URL on the data-href attribute (I used Google in the sample below):

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

<div class="fb-like" data-href="http://www.google.com" data-width="450" data-layout="button_count" data-show-faces="false" data-send="false"></div>
That Brazilian Guy
  • 3,328
  • 5
  • 31
  • 49
-4

If you're developing the likebutton for www.xyz.com, just add in your hosts file:

127.0.0.1 www.xyz.com

Hooray, no more 500s.

Alkanshel
  • 4,198
  • 1
  • 35
  • 54
  • 1
    This works considering that you already have a website at `www.xyz.com` with same pages as in your localhost. – Beebee Jan 22 '14 at 10:56