动态Facebook赞按钮

时间:2013-02-16 23:45:17

标签: php javascript facebook facebook-like

我有各种各样的页面:

www.mysite /目录/标题?标题= $标题

所以你可以看到每个页面都是动态的。在我想要为动态网址生成按钮之前已经多次询问过。我注意到去年年底的类似按钮有一些变化,所以一直试图找到有关这方面的最新帖子。

我遇到的问题是Facebook错误,它指出它需要一个绝对网址,或者它只是将类似按钮引用到Facebook设置的内容,在这种情况下是我的登录页面。

我尝试了以下内容:

    // Load the SDK's source Asynchronously
  // Note that the debug version is being actively developed and might 
  // contain some type checks that are overly strict. 
  // Please report such bugs using the bugs tool.
  (function(d, debug){
     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" + (debug ? "/debug" : "") + ".js";
     ref.parentNode.insertBefore(js, ref);
   }(document, /*debug*/ false));
</script>

    <script type="text/javascript">
      var sUrl = "http://www.mysite.com/";
      document.getElementById('fb').setAttribute('href', sUrl);
    </script>  
<div class="fb-like" id="fb"  data-send="true" data-layout="button_count" data-width="60" data-show-faces="true"></div>

// Load the SDK's source Asynchronously // Note that the debug version is being actively developed and might // contain some type checks that are overly strict. // Please report such bugs using the bugs tool. (function(d, debug){ 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" + (debug ? "/debug" : "") + ".js"; ref.parentNode.insertBefore(js, ref); }(document, /*debug*/ false)); </script> <script type="text/javascript"> var sUrl = "http://www.mysite.com/"; document.getElementById('fb').setAttribute('href', sUrl); </script> <div class="fb-like" id="fb" data-send="true" data-layout="button_count" data-width="60" data-show-faces="true"></div>

以及:

<?php $url = basename($_SERVER['REQUEST_URI']);?>
<div class="fb-like" data-send="false" data-layout="button_count" data-width="450" data-show-faces="true"></div>

并且不要忘记:

  <div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=186609524720286&amp;xfbml=1"></script>
<div id="fblikeblock"></div>
<script>
    var url = 'http://apps.facebook.com/inflatableicons/image_preview.html?y=120';
    jQuery("#fblikeblock").html('<fb:like id="fbLike" href="'+url+'" send="true" width="450" show_faces="true" font=""></fb:like>');
    FB.XFBML.parse(document.getElementById('fblikeblock'));
    console.log(document.getElementById('fblikeblock'));
  </script>

调用FB.XFBML.parse。

我没有成功,但正如你所看到的那样现在已经用很多方法尝试过了,而且我很困难。有什么想法吗?

谢谢!

编辑:

网址是编码的,所以今天我尝试了以下内容 - 结果仍然相同。我在Stack上看到的所有地方都说这些方法都应该有效,但我无处可去:

<fb:like></fb:like>

有什么想法吗?

1 个答案:

答案 0 :(得分:0)