title: Retrieve data from facebook api for a user
body: <p>Hey so I am having a hard time understanding how to retrieve data from a user who logs in to my site, I am currently using the javascript sdk but I am trying to figure out how to request the user's data correctly and then how to send it to my server side... I thought it might be something like </p>
  
  <pre><code>req.body.id 
  </code></pre>
  
  <p>for the facebook user id, but I do not think that is it...</p>
  
  <p>Here is the javascript code  on my login page.</p>
  
  <pre><code>script(src='//connect.facebook.net/en_US/all.js')
  div#fb-root
      script.
              window.fbAsyncInit = function() {
                  // init the FB JS SDK
              FB.init({
                  appId: 'blank', // App ID from the app dashboard
                  //channelUrl:'//WWW.YOUR_DOMAIN.COM/channel.html', // Channel file for x-domain comms
                  status     : true,                                 // Check Facebook Login status
                  xfbml      : true,                                  // Look for social plugins on the page
                  cookie: true
              });
  
  
  
          };
  
  
  
          (function(d){
              var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
              if (d.getElementById(id)) {return;}
              js = d.createElement('script'); js.id = id; js.async = true;
              js.src = "//connect.facebook.net/en_US/all.js";
              ref.parentNode.insertBefore(js, ref);
          }(document));
  
  
          function authUser() {
                  FB.login(checkLoginStatus, {scope:'email, user_likes'});
  
                  function checkLoginStatus(response) {
                      if(response &amp;&amp; response.status == 'connected') {
                          alert('User is authorized');
                          document.getElementById('loginButton').style.display = 'none';
                          console.log('Access Token: ' + response.authResponse.accessToken);
                          var uid = response.authoResponse.userID;
                          var accessToken = response.authoResponse.accessToken;
              testAPI();
                          getFBData ();
                      } else {
                          alert('User is not authorized');
                          document.getElementById('loginButton').style.display = 'block';
                      }
                  }
  
  
              }
  
  
          function testAPI() {
              console.log('Welcome!  Fetching your information.... ');
              FB.api('/me', function(response) {
                  console.log('Good to see you, ' + response.name + '.' + response.id);
              });
          };
  
          function getFBData () {
              FB.api('/me', function(data){
                  alert(data.first_name + data.last_name + data.id);
              })
          };
          function fbLogout() {
              FB.logout(function (response) {
                  //window.location.replace("http://stackoverflow.com"); is a redirect
                  window.location.reload();
              });
          }
  
  
  
  
      div.centerContent
              form(method="POST", action="/login")
                  fieldset
                      legend Login
                      input(type="email", name="email", placeholder="Email", maxlength="20", value= "")   
                      br
                      input(type="password", name="password", id="password", placeholder="Password", maxlength="20", value= "")   
                      br
                      input.btn.btn-primary(type="submit", name="login", value="Login")
                      a(href="/")
                          button.btn(type="button") Cancel
              &lt;fb:login-button show-faces="true" width="200" max-rows="1"&gt;&lt;/fb:login-button&gt;
              button#fbLogout(type="button", onclick="fbLogout()") Logout of FB
              button#fbLogin(type="button", onclick="authUser()") Login to FB
  </code></pre>
  
  <p>It is in jade but it should be readable. </p>
  
  <p>Any help or direction on how to actually grab a user's info(in particular I am looking for a profile picture, access token, user id, first and last name)</p>
  
  <p>Thanks.</p>
  
  <p>EDIT: </p>
  
  <p>I am using node.js and mongodb on the backend</p>