我更喜欢给出stackoverflow问题的答案
Like button will not fire edge.create or edge.remove。
但是当我在crome浏览器的开发人员工具控制台中看到
时,我会收到以下错误"未捕获的ReferenceError:FB未定义为fb.php:20
应用程序配置不允许使用URL:应用程序的设置不允许使用一个或多个给定的URL。它必须与网站URL或Canvas URL匹配,或者域必须是App域之一的子域。"
代码如下
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<html xmlns:fb="http://ogp.me/ns/fb#">
<body>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=xxxxx";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
FB.Event.subscribe('edge.create',
function(response) {
alert('You liked the URL: ' + response);
}
);
FB.Event.subscribe('edge.remove',
function(response) {
alert('You UNliked the URL: ' + response);
}
);
</script>
<div class="fb-like" data-href="https://developers.facebook.com/docs/plugins/" data-layout="standard" data-action="like" data-show-faces="true" data-share="true"></div>
</body>
</html>
如何解决它请帮助我。
感谢你。
答案 0 :(得分:6)
您尚未初始化FB.init()
,否则您无法进行API调用 -
window.fbAsyncInit = function() {
FB.init({
appId : '510509449056378',
status : true,
xfbml : true
});
FB.Event.subscribe('edge.create',
function(response) {
alert('You liked the URL: ' + response);
}
);
FB.Event.subscribe('edge.remove',
function(response) {
alert('You UNliked the URL: ' + response);
}
);
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=510509449056378";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
答案 1 :(得分:0)
<!DOCTYPE html>
<head>
<title>
Like Box example
</title>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: '{APP_ID}'
});
FB.Event.subscribe('edge.create', function(response) {
alert('You liked the URL: ' + response);
});
FB.Event.subscribe('edge.remove',function(response) {
alert('You UNliked the URL: ' + response);
});
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id; //js.async = true;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId={APP_ID}";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<!--Like BOX-->
<fb:like-box href="https://developers.facebook.com/docs/plugins/" colorscheme="light" show_faces="false" header="false" stream="false" show_border="false"></fb:like-box>
</body>
</html>