2012-07-10 47 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>