Fetch facebook profile data using javascript

fetch Facebook profile data

Facebook is the most popular social networking site. Facebook provides graph api to get data  . We can fetch Facebook profile data using JavaScript also.

<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : 'Your Facebook App Id',
cookie : true,
xfbml : true,
version : 'v2.8'
});
};

(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 = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

function fbLoginFunction()
{
FB.login(function(response) {
if (response.authResponse)
{
FB.api('/me', 'get', { fields: 'id,name,gender,hometown,email' }, function(response) {
console.log(response);
});
} else {
alert("Login attempt failed!");
}
}, { scope: 'email,user_birthday,user_location,user_hometown,public_profile' });
}
</script>
<a href="javascript:void(0);" onclick="fbLoginFunction();" class="btn btn-primary btn-xl rounded-pill mt-5">Login</a>