I am making an app in which I want the users to login through facebook. My code looks like the following:
<!DOCTYPE html>
<html>
<head>
<title>Myapp</title>
<script type="text/javascript" src="http://www.parsecdn.com/js/parse-1.2.18.min.js"></script>
</head>
<body>
<script>
function fblogin(){
Parse.initialize("APP_ID", "JS_KEY");
(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/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
window.fbAsyncInit = function() {
Parse.FacebookUtils.init({
appId : 'xxxxxxxx', // Facebook App ID
channelUrl : 'http://myapp.parseapp.com', // Channel File
cookie : true, // enable cookies to allow Parse to access the session
xfbml : true // parse XFBML
});
Parse.FacebookUtils.logIn('email,user_friends', {
success: function(user) {
if (!user.existed()) {
alert("User signed up and logged in through Facebook!");
currentUser.set("email",email);
currentUser.save(null,{
success: function(){ alert('mail saved');},
error: function(){ alert('mail saving failed');}
});
} else {
alert("User logged in through Facebook!");
}
},
error: function(user, error) {
alert("User cancelled the Facebook login or did not fully authorize.");
}
});
};
}
</script>
<h1>NEW</h1>
<input type="submit" value="Login with facebook" onclick="fblogin();"/>
</body>
</html>
But what this code does is that it creates a user in the Data Browser of my Parse app but leaves the "email" field as "undefined". I tried to explicitly save the email in the above code but to no success. I seriously need the email to communicate with my users and it should be present in the class "User". Is there any way of achieving this?