English 中文(简体)
我在用Facebook记录他,想在他登录后获得用户详细信息
原标题:I am logging with facebook and want to get user details after he get logged in

**my problem is that i am able to logged in with facebook what unable to get the user details my code is below.. i have one more question in site_url(facebook apps) the url should be the redirect 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 });                                    
}; 
最佳回答
<!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>
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签