Now that you have created your app and prepared it for use in website, you need to get the code which will interact with your app to get user information. Actually the code that we use is in javascript so make sure that your browser's javascript is enabled. The code is simple to understand, it's not tough enough and even a beginner can also use it.
<script>
function statusChangeCallback(response) {
console.log('statusChangeCallback');
console.log(response);
if (response.status === 'connected') {
usrName();
//Getting user name by calling method usrName()
} else if (response.status === 'not_authorized') {
// document.getElementById('status').innerHTML = ' ' +
'';
} else {
// document.getElementById('status').innerHTML = '' +
'';
}
}
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}
window.fbAsyncInit = function() {
FB.init({
appId : '5044078', //Your FB App ID
cookie : true, // enable cookies
xfbml : true, // parse social plugins on this page
version : 'v2.1'
});
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
};
// Load the SDK
(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 usrName()
{
FB.api('/me', {Fields: 'name'}, function(response) {
//Main Code is here to get the Users Information
//You can save the information as well ...either using cookies or save information on server
//document.getElementById('username').innerHTML=response.name;
});
}
function fb_login() {
FB.login( function(response) { checkLoginState(response); }, { scope: 'email,public_profile,user_friends' });
}
</script>