How do I test the Facebook “Like” button on localh

2020-01-28 03:59发布

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

4条回答
仙女界的扛把子
2楼-- · 2020-01-28 04:34

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.

查看更多
神经病院院长
3楼-- · 2020-01-28 04:48

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>
查看更多
Ridiculous、
4楼-- · 2020-01-28 04:52

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.

查看更多
Lonely孤独者°
5楼-- · 2020-01-28 04:58

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.

查看更多
登录 后发表回答