Javascript FaceBook登录按钮错误:在调用FB.init()之前调用了FB.Login()
执行以下代码后,我收到此错误:Javascript FaceBook登录按钮错误:在调用FB.init()之前调用了FB.Login(),javascript,facebook,Javascript,Facebook,执行以下代码后,我收到此错误: <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 :
<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>
<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>
<fb:login-button show-faces="false" width="200" max-rows="1"></fb:login-button>
FB.init({
appId:“realidTheCode”,
状态:true,//检查登录状态
cookie:true,//启用cookie以允许服务器访问会话
xfbml:true//解析xfbml
});
我的想法是在登录()之前调用init()
但我仍然得到了那个错误:错误:在调用FB.init()之前调用了FB.login()
我现在有点不知所措,所以我非常感谢您的帮助:)试试下面的代码:
<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>
<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>
<fb:login-button show-faces="false" width="200" max-rows="1"></fb:login-button>
FB.init({
appId:“realidTheCode”,
状态:true,//检查登录状态
cookie:true,//启用cookie以允许服务器访问会话
xfbml:true//解析xfbml
});
我以前认为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>
//初始化API
window.fbAsyninit=函数(){
init({appId:'MYAPPID',状态:true,cookie:true,
xfbml:true});
};
(功能(){
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);
}());
Facebook登录
//您的fb登录功能
函数fblogin(){
FB.登录(功能(响应){
//用户已登录!
if(response.session){
警惕(“耶!”);
}否则{
//用户已取消登录
警惕(“不!”);
}
},{perms:'email,read_stream,publish_stream'});
}
或
<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>
FB.init({
appId:'MYAPPID',
状态:true,//检查登录状态
cookie:true,//启用cookie以允许服务器访问会话
xfbml:true//解析xfbml
});
Facebook登录
//您的fb登录功能
函数fblogin(){
FB.登录(功能(响应){
//用户已登录!
if(response.session){
警惕(“耶!”);
}否则{
//用户已取消登录
警惕(“不!”);
}
},{perms:'email,read_stream,publish_stream'});
}
参考:
我三次检查了我是否使用了正确的app id。但仍然没有任何结果:(