Facebook Like button event do not work
There are many POST indicating that once a user click on your Like button, it arises an event that you can catch like 开发者_如何学运维the next code:
window.fbAsyncInit = function() {
//Your app details here
FB.init({appId: '110981675649741', status: true, cookie: true, xfbml: true});
FB.Event.subscribe('edge.create', function(href, widget) {
alert('You just liked '+href);
});
FB.getLoginStatus(function(response) {
It seems that now, this do not work.
Does anyone know why? Did Facebook team change the way you get such event?
Use this code.
<div id="fb-root"></div>
<script type="text/javascript">
<!--
window.fbAsyncInit = function () {
FB.init({ appId: 'AppID', status: true, cookie: true, xfbml: true });
FB.Event.subscribe('edge.create', function (href, widget) {
// Do something, e.g. track the click on the "Like" button here
// alert('You just liked ' + href);
// alert('You just liked ' + widget);
window.location = "http://www.google.com";
});
};
(function () {
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
} ());
//-->
</script>
It will work.
Thanks
精彩评论