TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Get User Details by Facebook Login Authentication
Satyajeet Kumar
Feb 06
2016
Code
4.2
k
0
3
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
Default.aspx
<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#xfbml=1"
;
ref
.parentNode.insertBefore(js,
ref
);
}(document));
</script>
<%--https:
//developers.facebook.com/apps/YourAppId/review-status/--%>
<%-- Use link to check app status
for
live --%>
<script src=
"https://connect.facebook.net/en_US/all.js"
type=
"text/javascript"
></script>
<div>
<script src=
"http://code.jquery.com/jquery-1.8.0.min.js"
type=
"text/javascript"
></script>
<script>
$(
"document"
).ready(function () {
// Initialize the SDK upon load
FB.init({
appId:
'YourAppId'
,
// App ID
//channelUrl: '//' + window.location.hostname + '/Facebook.aspx', // Path to your Channel File
channelUrl:
'YourPageURL'
,
scope:
'id,name,gender,user_birthday,email'
,
// This to get the user details back from Facebook
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'
, OnLogin);
});
function OnLogin(response) {
if
(response.authResponse) {
FB.api(
'/me?fields=id,name,gender,email,birthday'
, LoadValues);
}
}
//This method will load the values to the labels
function LoadValues(me) {
if
(me.name) {
document.getElementById(
'displayname'
).innerHTML = me.name;
document.getElementById(
'FBId'
).innerHTML = me.id;
document.getElementById(
'DisplayEmail'
).innerHTML = me.email;
document.getElementById(
'Gender'
).innerHTML = me.gender;
document.getElementById(
'DOB'
).innerHTML = me.birthday;
document.getElementById(
'auth-loggedin'
).style.display =
'block'
;
var label = document.getElementById(
"Label1"
);
var textbox = document.getElementById(
"TextBox1"
);
label.innerText = me.email;
//textbox.nodeValue = label.innerText;
document.getElementsById(
"TextBox1"
).value = me.email;
}
}
</script>
</div>
<div id=
"fb-root"
>
</div>
<!-- This initializes the FB controls-->
<div
class
=
"fb-login-button"
autologoutlink=
"true"
scope=
"user_birthday,email"
>
Login with Facebook
</div>
<!-- FB Login Button -->
<!-- Details -->
<div id=
"auth-status"
>
<div id=
"auth-loggedin"
style=
"display: none"
>
Hi, <span id=
"displayname"
></span>
<br />
Your Facebook ID : <span id=
"FBId"
></span>
<br />
Your Email : <span id=
"DisplayEmail"
></span>
<br />
Your Sex: <span id=
"Gender"
></span>
<br />
Your Date of Birth : <span id=
"DOB"
></span>
<br />
<asp:Label ID=
"Label1"
runat=
"server"
></asp:Label><br />
<asp:TextBox ID=
"TextBox1"
runat=
"server"
></asp:TextBox>
</div>
</div>
C#
Facebook Login Authentication