2012-01-02 207 views
0

我在我的項目中使用javascript代碼實現了Facebook登錄。它工作正常,但現在它不工作。登錄彈出窗口也不起作用。facebook登錄無法正常工作

代碼是在這裏

<fb:login-button autologoutlink="true" perms="email,user_birthday,status_update,publish_stream"></fb:login-button>

我改變燙髮到scope.the彈出來了,但劇本的問題依然存在。使用

腳本代碼:

<div id="fb-root"></div> 
    <script type="text/javascript"> 
     window.fbAsyncInit = function() { 
      FB.init({appId: 'APPID', status: true, cookie: true, xfbml: true}); 

      /* All the events registered */ 
      FB.Event.subscribe('auth.login', function(response) { 
       // do something with response 
       login(); 
      }); 
      FB.Event.subscribe('auth.logout', function(response) { 
       // do something with response 
       logout(); 
      }); 

      FB.getLoginStatus(function(response) { 
       if (response.session) { 
        // logged in and connected user, someone you know 
        login(); 
       } 
      }); 
     }; 
     (function() { 
      var e = document.createElement('script'); 
      e.type = 'text/javascript'; 
      e.src = document.location.protocol + 
       '//connect.facebook.net/en_US/all.js'; 
      e.async = true; 
      document.getElementById('fb-root').appendChild(e); 
     }()); 

     function login(){ 
      FB.api('/me', function(response) { 
       fqlQuery();//fqlquery function 

      }); 
     } 
     function logout(){ 
      document.getElementById('login').style.display = "none"; 
     } 



     function fqlQuery(){ 
      FB.api('/me', function(response) { 
       var query = FB.Data.query('select name, hometown_location, sex, pic_square from user where uid={0}', response.id); 
       query.wait(function(rows) { 

        document.getElementById('name').innerHTML = 
        'Your name: ' + rows[0].name + "<br />" + 
        '<img src="' + rows[0].pic_square + '" alt="" />' + "<br />"; 
       }); 
      }); 
     } 

是否有任何其他的方式來糾正這個問題?請幫助....

+0

請更清楚「不工作」 – hugomg 2012-01-02 12:55:00

回答

0

我想你在加載facebook javascript SDK時缺少來自querystring的APP ID。每https://developers.facebook.com/docs/reference/plugins/login/他們希望有某種原因

<div id="fb-root"></div> 
<script>(function(d, s, id) { 
    var js, fjs = d.getElementsByTagName(s)[0]; 
    if (d.getElementById(id)) return; 
    js = d.createElement(s); js.id = id; 
    js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=APP_ID"; 
    fjs.parentNode.insertBefore(js, fjs); 
}(document, 'script', 'facebook-jssdk'));</script> 

此外,我注意到,您的登錄按鈕HTML沒有正確的屬性。根據文檔,show-faceswidthmax-rowsscope是唯一有效的參數。