簡體   English   中英

將facebook like按鈕與查詢字符串一起使用-like button不起作用

[英]Using the facebook like button with query strings - like button doesn't work

我將facebook的Like按鈕和Comments API整合到我的網站中(最后)。 現在,在我的網站上,我有一個頁面使用查詢字符串來確定正確的內容(我的網站有4000多個條目,我們使用此查詢字符串)。 因此,對於用戶來說,這一頁看起來像很多,就像這樣想...

productPage.php?productID=1234

現在,我可以毫無問題地添加注釋API,它可以區分URL / querystring的不同,這是非常好的。 但是,“贊”按鈕不起作用。 您單擊它,它閃爍並返回原來的狀態(它沒有注冊Like)。 我正在正確編碼網址(請參見下文)

<?php
   $fbUrl = urlencode("https://" . $_SERVER["HTTP_HOST"] . $_SERVER['REQUEST_URI']);
   // echo "this page is " .  $fbUrl;
?>

<script>

 window.fbAsyncInit = function() {
        FB.init({
          appId      : 'XXXXXXXXXXXXXXXXX', // App ID
          channelUrl : '//www.myURL.co.uk/channel.php', // Channel File
          status     : true, // check login status
          cookie     : true, // enable cookies to allow the server to access the session
          xfbml      : true  // parse XFBML
        });

        // Additional initialization code here
      };

</script>

Oh I love this content....
<br><br>

<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=205472122918257";
    fjs.parentNode.insertBefore(js, fjs);
 }(document, 'script', 'facebook-jssdk'));
</script>

<div class="fb-like" data-href="<?php echo $fbUrl; ?>" data-send="true" data-width="450" data-show-faces="false"></div>
<br><br>
and add a comment...
<br><br>
<div class="fb-comments" data-href="<?php echo $fbUrl; ?>" data-num-posts="2" data-width="470" data-colorscheme="dark"></div>

我已經花了幾個小時在此上,並注意到其他人也遭受了這一痛苦,但是似乎沒人能找到解決方案。 當我在網上拖網尋找解決方案時,是否有人可以解決此問題?

您是否使用開放式圖形調試器檢查了頁面?

https://developers.facebook.com/tools/debug

引用:

https://developers.facebook.com/docs/reference/plugins/like/ (在“喜歡”按鈕上)

https://developers.facebook.com/docs/reference/javascript/ (在FB JavascriptSDK上)

此處的不同之處在於腳本的重新排序。 此外,此示例中還包括XFBML(作為您使用的HTML5方法的替代方法)。

<html xmlns:fb="http://ogp.me/ns/fb#">
<head>....</head>
<body>
    <div id="fb-root"></div>
    <script>
      window.fbAsyncInit = function() {
        // init the FB JS SDK
        FB.init({
          appId      : 'YOUR_APP_ID',                        // App ID from the app dashboard
          channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel file for x-domain comms
          status     : true,                                 // Check Facebook Login status
          xfbml      : true                                  // Look for social plugins on the page
        });

        // Additional initialization code such as adding Event Listeners goes here
      };

      // Load the SDK asynchronously
      (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'";
         fjs.parentNode.insertBefore(js, fjs);
       }(document, 'script', 'facebook-jssdk'));
    </script>

    <fb:like href="<?php echo $fbUrl; ?>" send="true" width="450" show_faces="true"></fb:like>
</body>
</html>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM