2011-02-05 9 views
3

私はこのコードを実行した後、このエラーを取得しています:Facebookログインボタンのエラー:FB.login()FB.initを(呼び出す前に呼ばれる)

前に、init()メソッドを呼び出している私の考えに
<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> 

をFB.init()を呼び出す前にエラー:FB.login()が呼び出されました。

私は、この時点で総混乱のようなものにしていますので、私は助けを本当に感謝:)

+0

なぜ「fb-root」div要素とfacebook javascript用の2つのスクリプト要素がありますか? –

+0

私はやっていることや、ここで物事を行く正しい方法で少し失われているので、おそらく:) – Genadinik

答えて

1

私の場合、アプリ自体に問題があることが判明しました。だから私はFBで古いアプリを削除し、新しいものを作って、物事が始まったばかりです。

2

このコード試してみてください。

<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> 
+0

それを試して、動作しませんでした。私はそれがComeHike.comサイトの他のものと何か関係があるという疑いを持っています。誰かが珍しいものを見つけることができるかどうか分かりませんか? – Genadinik

4

を私は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> 

OR

<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> 

をしました:

+0

私はそれのためのテストページを作った:http://www.comehike.com/test_fb_connect.php - 試してみてください...動作しません:( – Genadinik

+0

@ゲナディニクおそらく間違ったAPPIDを参照してくださいここを参照http: //stackoverflow.com/questions/2855784/facebook-graph-api-fb-login-called-before-calling-fb-init – Nishant

+0

@GenadinikおそらくNot。Facebookに関連するすべてのJSを削除できますか? Nishant

関連する問題