2012-05-26 81 views
-1

**我的问题是我能够用facebook登录什么无法获取用户详细信息我的代码在下面..我还有一个问题在site_url(Facebook应用程序)的网址应该是重定向的URI? **我正在用facebook登录,想在登录之后获取用户详细信息

<script type="text/javascript"> 
window.fbAsyncInit = function() {               
    FB.init({appId: '*******', status: true, cookie: true,       
      xfbml: true});                 
    FB.Canvas.setAutoResize();                
    FB.getLoginStatus(function(response) {              
    if (response.session) {                 
    FB.api('/me', function(response) {              
     $('#name').val(response.first_name);        



    });                      
} else {                     
    // no user session available, someone you dont know          
    }                       
});                       
    };                       
    (function() enter code here{                    
    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);          
    }());                      

    function fblogin() {                  
FB.login(function(response) {               
    if (response.session) {                 
    if (response.perms) {                 
     // user is logged in and granted some permissions.          
     // perms is a comma separated list of granted permissions        
    } else {                     
     // user is logged in, but did not grant any permissions        
    }                      
    } else {                     
    // user is not logged in                 
    }                       
}, {perms:'read_stream,publish_stream,offline_access'});          
}; 
+0

如果你告诉我什么是错在it.anyways上帝保佑你,而不是消极的投票...我得到了我的解决方案,它的下面 – sandeepKumar

回答

0
<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml" > 
    <head> 

    </head> 
    <body> 
    <div id="mainBody"> 
     <div id="login_panel"> 
      <div id="fb-root"></div>   
      <script type="text/javascript"> 
       window.fbAsyncInit = function() { 
        FB.init({appId: 'YOUR APP ID', 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(); 
         } 
        }); 
        FB.getLoginStatus(function(response) { 
         login(); 
         logout(); 
        }); 
        }; 
        (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) { 

         if(typeof response.name != 'undefined') 
         { 
          document.getElementById('login').style.display = "block"; 
          document.getElementById('name').innerHTML = 'Name = ' + response.name; 
          document.getElementById('email').innerHTML = 'Email = ' + response.email; 
          document.getElementById('birthday').innerHTML = 'BirthDay = ' + response.birthday; 
          document.getElementById('username').innerHTML = 'Username = ' + response.username; 
          document.getElementById('bio').innerHTML = 'Bio = ' + response.bio; 
         } 

        }); 
        } 

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

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

      <div id="login"> 

       <div id="name"></div> 
       <div id="email"></div> 
       <div id="birthday"></div> 
       <div id="username"></div> 
       <div id="bio"></div>    
      </div> 
     </div><!-- end login_panel --> 

    </div><!-- end mainBody --> 


    </body> 
</html> 
+0

你能解释一些添加到此? –

+0

早些时候我有问题,当我用Facebook登录我的页面不刷新,以便它可以读取FB.api('/我')的功能,bcoz我测试,我想在同一页上的结果,现在(); });使用函数FB.Event.subscribe('auth.login'它得到了回应 – sandeepKumar

相关问题