How do I test the Facebook "Like" button on localhost?
Solution 1
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.
Solution 2
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.
Solution 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>
Tomasz Gutkowski
Hi, I am a Java programmer. Deals mainly with web applications. At work I use technologies such as JSF and Struts2. Interests: Programming Favorite sports: Football, Cycling.
Updated on August 30, 2020Comments
-
Tomasz Gutkowski almost 4 years
It is possible to test "Like" button on localhost?
-
Dave almost 12 yearsRelated 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'.
-
svassr almost 12 yearslocaltunnel is really convenient to test sharing meta description, title and image.
-
Admin about 11 yearsThanks M.G.Palmer, localtunnel.com works like a charm! Here an announcement about localtunnel version 2: progrium.com/blog/2012/12/25/localtunnel-v2-available-in-beta Github: github.com/progrium/localtunnel/blob/master/README.md
-
Beebee over 10 yearsThis works considering that you already have a website at
www.xyz.com
with same pages as in your localhost. -
Dan Ross over 9 yearsNew url: localtunnel.me