title: Retrieve first and last name after login via facebook
body: <p>I managed to login via facebook api (I think). This is my code:</p>
  
  <pre><code>&lt;script&gt;
    window.fbAsyncInit = function() {
      FB.init({
        appId            : '134824563795810',
        autoLogAppEvents : true,
        xfbml            : true,
        version          : 'v2.10'
      });
      FB.AppEvents.logPageView();
    };
  
    (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/sdk.js";
       fjs.parentNode.insertBefore(js, fjs);
     }(document, 'script', 'facebook-jssdk'));
  
     function myFacebookLogin() {
      FB.login(function(){}, {scope: 'publish_actions'});
      }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>And simple button just to test if this works:</p>
  
  <pre><code>&lt;button onclick="myFacebookLogin()"&gt;Kontynuuj przez facebook&lt;/button&gt;
  </code></pre>
  
  <p>After clicking on it I receive this pop up:</p>
  
  <p><a href="https://i.stack.imgur.com/FgkZI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FgkZI.png" alt="enter image description here"></a></p>
  
  <p>I click OK, and I think I'm logged in. Another click generates small popup windows, that disappear quickly. I said I think I'm logged in, because I don't use any authorization on my website. I don't need it.</p>
  
  <p>My question is: if I'm logged in, how can I get the user's first and last name and put this values into my bracket input?</p>
  
  <p><a href="https://i.stack.imgur.com/U2yrM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/U2yrM.png" alt="enter image description here"></a></p>
  
  <p>I want to make script only put values into inputs. Like:</p>
  
  <ul>
  <li><code>Imię</code> -> <code>first name</code></li>
  <li><code>Nazwisko</code> -> <code>last name</code></li>
  </ul>
  
  <p>Any suggestions?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I finally came up with this code:</p>
  
  <pre><code>&lt;script&gt;
  function getUserData() {
          FB.api('/me?fields=first_name,last_name,email,location', function(response) {
                  var imie = document.getElementById('basketInputName');
                  if(!imie || !imie.value)
                      imie.value = response.first_name;
                  var nazwisko = document.getElementById('basketInputLastName');
                      if(!nazwisko || !nazwisko.value)
                          nazwisko.value = response.last_name;
                  var email = document.getElementById('basketInputMail');
                      if(!email || !email.value)
                          email.value = response.email;
                  var location = document.getElementById('cityToHidden');
                      if(!location || !location.value)
                          location.value = response.location.name;
          });
  }
    window.fbAsyncInit = function() {
  
  
  FB.init({
    appId            : '134824563795810',
    autoLogAppEvents : true,
    xfbml            : true,
    version          : 'v2.10'
  });
  FB.getLoginStatus(function(response) {
          if (response.status === 'connected') {
                  //user is authorized
                  document.getElementById('loginBtn').style.display = 'none';
                  getUserData();
          } else {
                  //user is not authorized
          }
  });
    };
  
    (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/sdk.js";
   fjs.parentNode.insertBefore(js, fjs);
     }(document, 'script', 'facebook-jssdk'));
  
     function myFacebookLogin() {
  FB.login(function(){
      getUserData();
  }, {scope: 'user_location'});
  }
  </code></pre>
  
  <p></p>
  
  <p>But it's not working how i would like. When i click <code>loggin</code> button nothing happens, but when i refresh page, and check bucket i see that <code>firstName</code>, <code>lastName</code> and <code>email</code> are in inputs. And i don't know how to make dynamicly fill inputs by clicking on <code>login</code> button without refreshing page.
  Can somebody help?</p>