-1

**我的问题是我可以使用 facebook 登录什么无法获取用户详细信息我的代码在下面。我在 site_url(facebook 应用程序)中还有一个问题,url 应该是重定向 uri?**

<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'});                                    
}; 
4

1 回答 1

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>
于 2012-05-28T07:12:43.200 回答