It is possible to test "Like" button on localhost?
4 Answers
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.

- 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
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.
-
localtunnel is really convenient to test sharing meta description, title and image. – svassr Sep 12 '12 at 20:18
-
1Thanks 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
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>

- 3,328
- 5
- 31
- 49
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.

- 4,198
- 1
- 35
- 54
-
1This 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