2013-01-24 26 views
0

我使用以下代碼進行Facebook身份驗證。Facebook的JavaScript sdk不woking

<html> 
<head> 
</head> 
<body> 
    <div id="fb-root"></div> 
    <script> 
    window.fbAsyncInit = function() { 
     FB.init({ 
     appId  : '498085136....', 
     status  : true, 
     cookie  : true, 
     xfbml  : true, 
     oauth  : true, 
     }); 
    }; 
    (function(d){ 
     var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} 
     js = d.createElement('script'); js.id = id; js.async = true; 
     js.src = "//connect.facebook.net/en_US/all.js"; 
     d.getElementsByTagName('head')[0].appendChild(js); 
    }(document)); 

    //LOGIN FUNCTION 
    function login() { 
    FB.login(function(response) { 
     if (response.authResponse) { 
      alert('Success!'); 
     }else{ 
      alert('Login Failed!'); 
     } 
    }, {scope: 'email'}); 
} 
    </script> 
    <div onclick="login();">Login with Facebook</div> 
</body> 
</html> 

我不知道那段代碼有什麼問題。當我檢查我的錯誤控制檯,它顯示FB沒有被定義..

在此先感謝。

回答

0

讓你的HTML標籤類似這樣的

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">