2012-07-10 79 views
0

有誰能告訴我爲什麼回調不能用於下面給出的類似按鈕的代碼?就我所見,該代碼是JavaScript中設置的標準。第一個按鈕被初始化,然後API被異步加載,並提供回調函數。FaceBook像按鈕回調不起作用

<div id="fb-root"></div> 
<script> 

window.fbAsyncInit=function(){ 
    FB.init({ 
     appId:'',//App ID 
     status:false,// check login status 
     cookie:true,// enable cookies to allow the server to access the session 
     xfbml:true// parse XFBML 
    }); 
    // Additional initialization code here 

    FB.Event.subscribe('edge.create', function(response) { 
     //alert("user_id1:<?php echo $user_id1; ?>, user_id2:<?php echo $user_id2; ?>"); 
     /*var data={ 
      action:"ap_buttons_give_points", 
      author_id:<?php echo $author_id; ?>, 
      post_id:<?php echo $post_id; ?>, 
      type:"like" 
     } 

     jQuery.post("<?php echo $ajax_url; ?>",data,function(resp){ 

     });*/ 
    alert('You just liked the page!'); 
}); 

    FB.Event.subscribe('edge.remove', function(response) { 
     /*var data={ 
      action:"ap_buttons_take_points", 
      author_id:<?php echo $author_id; ?>, 
      post_id:<?php echo $post_id; ?>, 
      type:"like" 
     } 

     jQuery.post("<?php echo $ajax_url; ?>",data,function(resp){ 
      //alert("fb remove:"+resp); 
     });*/ 
    alert('You just unliked the page!'); 
}); 
}; 

// 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

該按鈕是HTML5。代碼是:

。在這種情況下如何定義回調? – 2012-07-10 18:04:05

+0

我也得到這個:FB.init已經被調用 - 這可能表明一個問題 – 2012-07-10 18:10:21

回答

0

是,代碼似乎罰款。我有點相同的問題,但只有fb像按鈕,iframe版本。 我沒有在你的例子中看到fb按鈕,所以我不知道你使用哪一個......所以,從我的經驗來看,使用標準fb就好。

0

我唯一發生這種情況的是當我使用iframe版本的Like按鈕時。我發現回調在該版本中根本不起作用。如果是這樣的話,你要使用JavaScript SDK版本發現here,或者使用XFBML或HTML5:

<fb:like send="true" width="450" show_faces="true"></fb:like> 

<div class="fb-like" data-send="true" data-width="450" data-show-faces="true"></div>