2011-11-06 82 views
1

我想解雇这个Facebook的事件,但它不工作?想实现一些视图跟踪,也许我有错误的方法?如何触发FB事件?

<!doctype html> 
<html lang="en" xmlns:fb="https://www.facebook.com/2008/fbml"> 
<head> 
    <meta charset="utf-8"> 
    <title>Facebook Like Button</title> 
</head> 
<body> 
<div id="fb-root"></div> 
<script type="text/javascript"> 


    window.fbAsyncInit = function() { 
     FB.init({ appId: 'xxxx', status: true, cookie: true, 
      xfbml: true 
     }); 
     FB.Event.subscribe('edge.create', function (href, widget) { 
      alert('Facebook Like'); // I would like to call some tracking functionality here but does not fire:(
      console.log('like'); 
     }); 
    }; 
    (function() { 
    var e = document.createElement('script'); e.async = true; 
    e.src = document.location.protocol + 
     '//connect.facebook.net/en_US/all.js'; 
    document.getElementById('fb-root').appendChild(e); 
    }()); 


</script> 
<fb:like></fb:like> 
</body> 
</html> 

回答

1

你试图为了单元测试而开启它吗?如果是这样,请尝试:FB.Event.fire('edge.create');

0

或者只是放置一个按钮? 为了测试的目的,这可能指向一个脸书页面,所以你可以实际上不像该页面,然后再试一次...

+0

你可以不像使用类似按钮。当你将鼠标悬停在它上面时,会出现一个小的“x”,它可以让你不同。 –