Facebook Share 按钮不会显示在 Chrome 中

Facebook Share button won't display in Chrome

本文关键字:Chrome 显示 Share 按钮 Facebook      更新时间:2023-09-26

我正在构建一个rails应用程序,但我无法在Chrome或Firefox中显示Facebook Share按钮。 它在IE和Safari中显示正常。"赞"和"登录"按钮在所有浏览器中都能正常工作。 我在网上搜索过,但找不到任何有用的东西。

在我拥有的每一页上

<!-- Facebook SDK -->
<div id="fb-root"></div>
<script>
window.onload = function()
{
  // Additional JS functions here
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'XXXXXXXXXXXXXXX', // App ID
      channelUrl : '//localhost:3000/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });
  (function(d){
   var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
   if (d.getElementById(id)) {return;}
   js = d.createElement('script'); js.id = id; js.async = true;
   js.src = "//connect.facebook.net/en_US/all.js";
   ref.parentNode.insertBefore(js, ref);
  }(document));
}

在我希望显示"共享"按钮的页面上,我有

<fb:share-button type="button_count"></fb:share-button>

根据亚当的建议,我创建了一个HTML文件。 出现登录按钮,但共享按钮没有

<!DOCTYPE HTML>
<HTML xmlns:fb="http://ogp.me/ns/fb#">
<HEAD>
   <TITLE>Untitled HTML Document</TITLE>
</HEAD>
<BODY BGCOLOR="white">
<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&appId=MY_APP_ID"; // APP ID
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
FB
<fb:share-button type="box_count"></fb:share-button> <br>
<div class="fb-login-button" data-width="200"></div>
</BODY>
</HTML>

看起来问题出在我使用本地主机作为我的网址上。 我更改了我的/etc/hosts 文件,以便 fakeurl.com 指向 127.0.0.1,现在工作正常。

xmlns:fb="http://ogp.me/ns/fb#"添加到<HTML>标签中:

<html xmlns:fb="http://ogp.me/ns/fb#">

更改<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&appId=YOUR_APP_ID"; // APP ID
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

现场演示