下面是我在我的网站上用于 Facebook Like 按钮(和 Share 按钮)的代码。
效果很好。我单击“赞”按钮,然后砰的一声,我的 Facebook 帐户的个人资料页面上出现了一个很好的通知。 Facebook 甚至会自动生成预览图像,而该图像恰好是我网站的 Logo 。精彩的。我网站上的 Like 计数器总计正确。
所以我想记录点赞按钮的点击次数。根据this页面,代码 FB.Event.subscribe('edge.create', function(response) {});
允许您执行此操作。
在下面的代码中,我应该把代码放在什么地方 FB.Event.subscribe('edge.create', function(response) {});
?
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<?php
echo '<div id="fb-root"></div>';
echo "<script type='text/javascript'>
window.fbAsyncInit = function() {
FB.init({appId: 'my_fb_app_id', status: true, cookie: true,
xfbml: true});
};
(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>";
echo '<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="" send="true" layout="button_count" width="450" show_faces="false" font="arial"></fb:like>';
?>
最佳答案
我不完全确定这是否正确,但根据 this stack overflow thread ,您将事件订阅代码放在 FB.init()
之后和匿名函数调用之前,
window.fbAsyncInit = function() {
FB.init({
appId : 'sensored-app-id',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
/* All the events registered */
FB.Event.subscribe('comments.add', function (response) {
// do something with response
alert("comment added");
});
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/fi_FI/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
此外,如果您看到 this developer's code example ,您会看到他也将事件订阅代码放在 Facebook 初始化代码之后。
关于php - 在哪里放置 FB.Event.subscribe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6448732/