Click here to Skip to main content
14,735,239 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to add the Facebook login to my site. I figured out how to add the app on Facebook and reference it in my code. When i test this, it pulls up the Facebook window, allows me to login, and changes the, "Login with Facebook" icon to, "Log Out". So it appears to be working somewhat, but I am unable to get the data from the login. I looked up tutorials to learn how to collect the Display Name, Gender, etc. I added a few alerts to the javascript to see what I could see, but I'm at a dead end. The call to the OnLogin method never seems to fire, so i can't see my response object values.
Also, I am using my actual APP_ID, I just removed it from the sample code below.

Thanks for any advice.

<script src="scripts/jquery-1.8.0.min.js" type="text/javascript"></script>
<script src="scripts/all.js" type="text/javascript"></script>
<script type="text/javascript">
$("document").ready(function () {
// Initialize the SDK upon load
FB.init({
appId: 'My Actual ID', // App ID
channelUrl: '//' + window.location.hostname + '/channel', // Path to your Channel File
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);
});

// This method will be called after the user login into facebook.
function OnLogin(response) {
alert('Testing');
if (response.authResponse) {
FB.api('/me?fields=id,name,gender,email,birthday', LoadValues);
alert(me.name);
}
}

//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';

alert(me.name);
}
}
</script>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900