Facebook API-FB.Event.subscribe('edge.create')不起作用 [英] Facebook API - FB.Event.subscribe('edge.create') not working
问题描述
花了数小时在网上拖曳,我发现许多与此相关的帖子,但似乎都没有用,即使是jsfiddle上的一些可用"示例也似乎无法使用!
Having spent hours trawling the web I have found many posts related to this but none seem to work, even some 'working' examples on jsfiddle appear not to work!
我想在用户单击我的网页上的喜欢"时进行注册.
I want to register when a user clicks 'like' on my web page.
出现喜欢"链接,实际上它会弹出一个新窗口供您登录Facebook.但是我不能订阅'edge.create'事件.我知道sdk加载正常,因为我可以订阅'xfbml.render'事件.
The 'like' link appears and indeed it pops up a new window for you to log into facebook. But I cannot subscribe to the 'edge.create' event. I know the sdk is loading ok because I can subscribe to the 'xfbml.render' event.
有些帖子说您必须具有一个appId才能运行此功能(我愿意),但其他人则声称它不能运行.
Some posts say that you must have an appId for this to work [I do] but others claim that it works without.
这是我的代码:
需要注意的一点是,我目前正在//localhost:57477下运行此文件,因此我已将like href设置为google.com.我确实注意到,其中一篇文章指出了一个最近的Facebook错误,如果href域与网页域不匹配,则不会触发此事件,但是现在将其标记为已修复".
One point to note is that I am currently running this under //localhost:57477, so I have set the like href to google.com. I did note that one of the posts indentified a recent facebook bug where this event didn't fire if the href domain didn't match that of the web page, but this is now marked as 'fixed'.
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function () {
//console.log('window.fbAsyncInit');
FB.init({
appId: 'myappid',
status: false,
cookie: false,
xfbml: true
});
//Additional initialization code here
FB.Event.subscribe('edge.create',
function (response) {
//console.log('edge.create');
alert('edge.create');
}
);
FB.Event.subscribe('xfbml.render',
function (response) {
//console.log('xfbml.render');
alert('xfbml.render');
}
);
};
// 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>
<div href="http://google.com" class="fb-like" data-send="false" data-width="450" data-show-faces="false" data-font="verdana"></div>
推荐答案
我知道这是旧线程,但是我来到这里时遇到了同样的问题. 对我有用的是,Facebook AppID必须属于您的站点所在的域(在Facebook App设置中对其进行设置)-本地主机将无法工作.
I know this is old thread, but i came here with the same problem. The thing that worked for me is that Facebook AppID must belong to a domain (set it in Facebook App settings) in which your site stands - localhost won't work then.
这篇关于Facebook API-FB.Event.subscribe('edge.create')不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!