Pranav Pranav

Pranav Pranav

  • NA
  • 1
  • 561

Facebook Login User Details

Aug 31 2016 6:41 AM
Hi
  I am intergrating  facebook login in website, after login i got user details using following code 
 
<html>
<head>
<title>Facebook Get Logged in User Details UserName,Email,Profile Image</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<form id ="form1" runat ="server" >
<script>
// Load the SDK Asynchronously
(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));
// Init the SDK upon load
window.fbAsyncInit = function () {
FB.init({
appId: '', // App ID
channelUrl: '//' + window.location.hostname + '/channel', // Path to your Channel File
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true // parse XFBML
});
// listen for and handle auth.statusChange events
FB.Event.subscribe('auth.statusChange', function (response) {
if (response.authResponse) {
// user has auth'd your app and is logged into Facebook
var uid = "http://graph.facebook.com/" + response.authResponse.userID + "/picture";
FB.api('/me?fields=id,name,gender,email,first_name,last_name,birthday,hometown,location', function (me) {
document.getElementById('authdisplayname').innerText = me.name;
document.getElementById('Email').innerText = me.email;
document.getElementById('firstname').innerText = me.first_name;
document.getElementById('lastname').innerText = me.last_name;
document.getElementById('gender').innerText = me.gender;
//document.getElementById('profileImg').src = uid;
document.getElementById('birthday').innerText = me.birthday;
document.getElementById('hometown').innerText = me.hometown.name;
document.getElementById('location').innerText = me.location.name;
var someValueToPass = me.email;
__doPostBack('CustomPostBack', someValueToPass);
})
document.getElementById('auth-loggedout').style.display = 'none';
document.getElementById('auth-loggedin').style.display = 'block';
} else {
// user has not auth'd your app, or is not logged into Facebook
document.getElementById('auth-loggedout').style.display = 'block';
document.getElementById('auth-loggedin').style.display = 'none';
}
});
$("#auth-logoutlink").click(function () { FB.logout(function () { window.location.reload(); }); });
}
</script>
<h1>
Facebook Login Authentication Example</h1>
<asp:TextBox ID="textbox1" runat ="server" ></asp:TextBox>
<div id="auth-status">
<div id="auth-loggedout">
<div class="fb-login-button" autologoutlink="true" scope="email,user_birthday,user_location,user_hometown,publish_actions" perms="user_location,user_about_me,user_birthday,user_hometown">Login with Facebook</div>
</div>
<div id="auth-loggedin" style="display: none">
<%--Name: <b><span id="auth-displayname"></span></b>(<a href="#" id="auth-logoutlink">logout</a>)<br />--%>
Name:<b><asp:Label runat ="server" ID="authdisplayname" Visible ="true" ></asp:Label></b>(<a href="#" id="auth-logoutlink">logout</a>)<br />
Email: <b><asp:Label runat ="server" ID ="Email" Visible ="true"></asp:Label> </b><br />
First Name:<b><asp:Label runat ="server" ID ="firstname" visible ="true"></asp:Label> </b><br />
Last Name:<b><asp:Label runat ="server" ID ="lastname" Visible ="true" ></asp:Label></b><br />
Gender:<b><asp:Label runat ="server" ID ="gender" Visible ="true"></asp:Label> </b><br />
<%--Profile Image: <img id="profileImg" /><br />--%>
Birthday:<b><asp:Label runat ="server" ID ="birthday" Visible ="true"></asp:Label> </b><br />
Hometown:<b><asp:Label runat ="server" ID="hometown" Visible ="true" ></asp:Label></b><br />
Location:<b><asp:Label runat ="server" ID ="location" Visible ="true" ></asp:Label></b><br />
</div>
</div>
</form>
</body>
</html>
 
Now i want save these details in database  using vb.net.... Anyone can guide
 
Thanks  
 
 
 
 

Answers (1)