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&amp;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&amp;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'});
}
参考:


对我来说,这是应用程序本身的问题。因此,我删除了FB中的旧应用程序并制作了一个新应用程序,事情才开始运作。

为什么facebook javascript有两个“FB root”div元素和两个script元素?很可能是因为我对我正在做的事情和正确的方法有点迷茫:)尝试过,没有成功。我怀疑这与ComeHike.com网站上的其他事情有关。不确定是否有人能在那里发现一些不寻常的东西?我为它做了一个测试页面:--试试看…不起作用:(@Genadinik可能偶然发现了错误的APPID,请看这里@Genadinik-hmm可能没有。你能试着删除所有与Facebook相关的JS吗?
我三次检查了我是否使用了正确的app id。但仍然没有任何结果:(