harendra dixit

harendra dixit

  • 1.5k
  • 147
  • 907

how to get first name and last name from facebook integratio

Aug 27 2015 4:54 AM
<html> <head>     <title>Facebook Login JavaScript Example</title>     <meta charset="UTF-8"> </head> <body>     <script>           function statusChangeCallback(response) {             console.log('statusChangeCallback');             console.log(response);               if (response.status === 'connected') {                  testAPI();             } else if (response.status === 'not_authorized') {                  document.getElementById('status').innerHTML = 'Please log ' +                   'into this app.';             } else {                   document.getElementById('status').innerHTML = 'Please log ' +                   'into Facebook.';             }         }            function checkLoginState() {             FB.getLoginStatus(function (response) {                 statusChangeCallback(response);             });         }           window.fbAsyncInit = function () {             FB.init({                 appId: 'app_key',                 cookie: true,                   xfbml: true,                 version: 'v2.4'             });                 FB.getLoginStatus(function (response) {                 statusChangeCallback(response);             });           };            (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 testAPI() {             console.log('Welcome!  Fetching your information.... ');             FB.api('/me', function (response) {                 console.log('Successful login for: ' + response.name);                 document.getElementById('status').innerHTML =                   'Thanks for logging in, ' + response.name + '!';                 $('#fName').val(response.first_name);                 $('#lName').val(response.lastst_name);             });         }     </script>        <fb:login-button scope="public_profile,email" onlogin="checkLoginState();">     </fb:login-button>       <div id="status">       </div>     First  Name:   <label id="fName"></label>     Last  Name:   <label id="lName"></label> </body> </html>