2011-11-02 55 views
1

我正在嘗試使用SDK Facebook來檢測likebox上的按鈕「like」並調用一個函數,但它不起作用。 這裏是我的代碼:關於點擊按鈕的Facebook Likebox事件

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://ogp.me/ns/fb#"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>Untitled Document</title> 
    </head> 

    <body> 
    </body> 

<div id="fb-root"></div> 
<script> 
    window.fbAsyncInit = function() { 
    FB.init({ 
     appId  : 'xxxx', // App ID 
     channelURL : 'xxxx/facebook/channel.html', // Channel File 
     status  : true, // check login status 
     cookie  : true, // enable cookies to allow the server to access the session 
     oauth  : true, // enable OAuth 2.0 
     xfbml  : true // parse XFBML 
    }); 

    // Additional initialization code here 
    }; 

    // Load the SDK Asynchronously 
    (function(d){ 
    var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} 
    js = d.createElement('script'); js.id = id; js.async = true; 
    js.src = "//connect.facebook.net/en_US/all.js"; 
    d.getElementsByTagName('head')[0].appendChild(js); 
    }(document)); 
</script> 
<script type="text/javascript"> 
FB.Event.subscribe('edge.create', 
    function(response) { 
     alert('You liked the URL: ' + response); 
    } 
); 
</script> 

<fb:like-box href="http://www.facebook.com/MarwenClubiiste" width="292" show_faces="false" stream="false" header="false"></fb:like-box> 

</html> 

請幫幫忙,我真的需要這個

回答

2

樣箱有一個已知的bug,其中如果用戶退出Facebook的,並具有edge.create事件不起作用登錄到LIKE頁面。 但是,如果用戶已經登錄正常工作 這裏是這個錯誤的一提:

https://github.com/facebook/connect-js/issues/82

http://forum.developers.facebook.net/viewtopic.php?id=75166

的Like按鈕沒有這個錯誤,並觸發事件這兩種情況。 您可能需要用Like按鈕+您自己的一些自定義HTML代替LikeBox。

嘗試使用facebook的非異步加載JS。這裏是更多的幫助:

http://forum.developers.facebook.net/viewtopic.php?id=87926

+0

好的非常感謝。 –