我有以下代码。在Google Chrome和Firefox上,它可以正常运行。但在IE11上,Facebook登录对话框不会出现。
当我在WPF应用程序中调用此网页时,我收到以下错误:
"FB" is undefined
在行
FB.getLoginStatus(function(response) {
以下是代码:
<html>
<head>
<title>Facebook</title>
<meta charset="UTF-8">
</head>
<body onload="checkLoginState();">
<div id="fb-root"></div>
<script>
function statusChangeCallback(response) {
}
function checkLoginState() {
document.getElementById('status').innerHTML = 'Welcome';
FB.getLoginStatus(function(response) {
testAPI();
});
}
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxxxxxxxxxxxxx',
cookie : true, // enable cookies to allow the server to access
// the session
xfbml : true, // parse social plugins on this page
version : 'v2.0' // use version 2.0
});
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
};
// Load the SDK asynchronously
(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 = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
// Here we run a very simple test of the Graph API after login is
// successful. See statusChangeCallback() for when this call is made.
function testAPI() {
FB.login(function(){
FB.api('/me/feed', 'post', {message: 'hello'},
function(response){if (!response || response.error)
{
document.getElementById('status').innerHTML = 'Error occured';
}
else
{
document.getElementById('status').innerHTML = 'OK';
}
}
);
}, {scope: 'publish_actions'});
}
</script>
<div id="status">
</div>
</body>
</html>
答案 0 :(得分:1)
FB
。仅在checkLoginState()
之后立即致电FB.init
。FB.login
,而不是在加载时。如果您不在用户事件上使用它,某些浏览器会阻止该对话框。顺便说一下,附注:您不能预填充message
/me/feed
publish_actions
参数,它必须始终是100%用户生成的,您必须完成审核流程才能为每个用户(而不仅仅是App管理员)提供{{1}}:https://developers.facebook.com/docs/apps/review