2012-05-18 64 views
7

我很沮喪,因爲我在這上面花了幾個小時 - 這裏也有其他線程,所以沒有人解決我的問題!爲什麼fb-like按鈕不出現?

我只是想在我的網站上實現類似fb的按鈕,www.posti.sh - 我想知道它爲什麼不起作用?

這裏是我使用的代碼,根據https://developers.facebook.com/docs/reference/plugins/like/步步教程:

<div id="fb-root"></div> (directly after the opening body tag) 

<div class="fb-like" data-href="http://www.posti.sh" data-send="true" data-width="450" data-show-faces="true"></div> 

其中我想的那樣。

我也在頭部添加了相應的meta標籤。

任何人都知道爲什麼它不起作用?

謝謝!

丹尼斯

更新1

我已經使用了FB調試工具https://developers.facebook.com/tools/debug,它只是說,OG圖像不夠大 - 我想這不應該是一個問題,但?

回答

4

它看起來像HTML5 Like Button代碼中的第1步缺少實際添加Javascript SDK的部分。代碼應該是:

<div id="fb-root"></div> 
<script> 
    window.fbAsyncInit = function() { 
    FB.init({ 
     appId  : 'YOUR_APP_ID', // App ID 
     channelUrl : '//WWW.YOUR_DOMAIN.COM/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 
    }); 

    // Additional initialization code here 
    }; 

    // Load the SDK Asynchronously 
    (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)); 
</script> 
+0

真棒,謝謝!它的工作原理,但我需要提供一個應用程序ID和文件channel.html?我沒有... – weltschmerz

+0

根據[FB.init文檔](https://developers.facebook.com/docs/reference/javascript/FB.init/),沒有,所有的參數都是可選的。 – freejosh

+0

非常感謝! – weltschmerz

0

剛纔我解決了類似的問題。 已顯示類似FB的按鈕,但未起作用。

在我的頁面<div id="fb-root"></div>divposition: relative; css屬性。 刪除後position: relative;它再次運作。