FB 评论事件 comment.create 和 comment.remove 不起作用
我正在尝试将事件侦听器添加到我的 Facebook 评论中。我尝试了在 Stack Overflow、FB 开发人员文档和旧开发人员论坛中找到的所有内容。 评论工作正常,我也可以调节它们,但事件根本没有被触发...我在一页上使用 FB 评论,并带有多个 fb:comments FBML 标签。这是我的 javascript 代码:
window.fbAsyncInit = function() {
FB.init({
appId: 'myAppId',
status: true,
cookie: true,
xfbml: true,
oauth: true
});
FB.Event.subscribe('comment.create',
function (response) {
console.log('create', response);
});
FB.Event.subscribe('comment.remove',
function (response) {
console.log('remove', response);
});
};
(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);
}());
和我的 HTML:
<fb:comments class="fb-comments" href="myFirstCommentUniqueURL" data-num-posts="2" data-width="440" notify="true" migrated="1"></fb:comments>
<fb:comments class="fb-comments" href="mySecondCommentUniqueURL" data-num-posts="2" data-width="440" notify="true" migrated="1"></fb:comments>
<fb:comments class="fb-comments" href="myThirdCommentUniqueURL" data-num-posts="2" data-width="440" notify="true" migrated="1"></fb:comments>
<fb:comments class="fb-comments" href="myFourthCommentUniqueURL" data-num-posts="2" data-width="440" notify="true" migrated="1"></fb:comments>
我在 Stack Overflow 上找到的有关 notification="true" 和 migerated="1" fb:comments 标记参数的提示,但它们没有帮助。我还检查了是否没有多个 init 调用,但整个页面上也是单个调用。
所以我不知道我做错了什么。
I am trying adding event listeners into my facebook comments. I tried probably everything I found here on Stack Overflow, also in FB developers docs and old developer forums.
Comments are working correctly, I can also moderate them, but events are not being fired at all... I am using FB comments on one page, with multiple fb:comments FBML tags. Here is my javascript code:
window.fbAsyncInit = function() {
FB.init({
appId: 'myAppId',
status: true,
cookie: true,
xfbml: true,
oauth: true
});
FB.Event.subscribe('comment.create',
function (response) {
console.log('create', response);
});
FB.Event.subscribe('comment.remove',
function (response) {
console.log('remove', response);
});
};
(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);
}());
and my HTML:
<fb:comments class="fb-comments" href="myFirstCommentUniqueURL" data-num-posts="2" data-width="440" notify="true" migrated="1"></fb:comments>
<fb:comments class="fb-comments" href="mySecondCommentUniqueURL" data-num-posts="2" data-width="440" notify="true" migrated="1"></fb:comments>
<fb:comments class="fb-comments" href="myThirdCommentUniqueURL" data-num-posts="2" data-width="440" notify="true" migrated="1"></fb:comments>
<fb:comments class="fb-comments" href="myFourthCommentUniqueURL" data-num-posts="2" data-width="440" notify="true" migrated="1"></fb:comments>
Hints about notify="true" and migrated="1" fb:comments tag parametrs I found here on Stack Overflow, but they did not help. I also checked if there isn't multiple init call, but it is also single on whole page.
So I have no idea, what I am doing wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你应该反转你的代码片段,因为你在尝试初始化 FB 对象后包含了所需的 javascript 文件。
所以代码应该是这样的
I think you should reverse your code snippet because you are including the required javascript file after you are trying to initialize the FB Object.
So the code should look like this