执行此代码后出现此错误:
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : 'realIdInTheCode',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
</script>
<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=realIdInTheCode&xfbml=1">
</script><fb:login-button show-faces="false" width="200" max-rows="1"></fb:login-button>
我的想法是在 login() 之前调用 init()
但我仍然收到错误:错误:在调用 FB.init() 之前调用了 FB.login()。
此时我有点困惑,所以非常感谢您的帮助:)
最佳答案
我曾经认为 FBML 已被弃用。我刚刚测试过,这对我有用
<html>
<head>
</head>
<body>
<div id="fb-root"></div>
<script>
//initializing API
window.fbAsyncInit = function() {
FB.init({appId: 'MYAPPID', 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>
<button type="button" onclick="fblogin();">Facebook Login</button>
<script>
//your fb login function
function fblogin() {
FB.login(function(response) {
//User logged in!
if (response.session) {
alert('YAY!');
} else {
// user cancelled login
alert('NAY!');
}
}, {perms:'email,read_stream,publish_stream'});
}
</script>
</body>
</html>
或
<html>
<head>
</head>
<body>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : 'MYAPPID',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
</script>
<button type="button" onclick="fblogin();">Facebook Login</button>
<script>
//your fb login function
function fblogin() {
FB.login(function(response) {
//User logged in!
if (response.session) {
alert('YAY!');
} else {
// user cancelled login
alert('NAY!');
}
}, {perms:'email,read_stream,publish_stream'});
}
</script>
</body>
</html>
引用:
关于javascript - FaceBook 登录按钮错误 : FB. 在调用 FB.init() 之前调用了 login(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4909638/