admin管理员组文章数量:1426620
I am using Facebook with Firebase Simple Login. I am trying to get the person's real name, which I have successfully done via user.displayName
in my FirebaseSimpleLogin instance. When I try getting their email with user.email
, it returns undefined
. I have done the same thing with Google+ and it works just fine, no undefineds returned. Here is my code:
var chatRef = new Firebase('https://******.firebaseio');
//No, i didn't actually put this firebase name in my code =P
var auth = new FirebaseSimpleLogin(chatRef, function(error, user) {
if (error) {
// an error occurred while attempting login
console.log(error);
alert('An error occurred while trying to log you in.' + error);
} else if (user) {
// user authenticated with Firebase
console.log('Name: ' + user.displayName + ', email: ' + user.email);
//With google, 'Name: John Doe, email: [email protected]' is returned
//With facebook, 'Name: John Doe, email: undefined' is returned
} else {
// user is logged out
}
});
function google() {
auth.login('google', {
rememberMe: true
});
}
function facebook() {
auth.login('facebook', {
rememberMe: true,
scope: 'email'
});
}
So, my question is, how can i get the user's email address with Facebook Firebase Simple Login? Thank you all in advanced.
I am using Facebook with Firebase Simple Login. I am trying to get the person's real name, which I have successfully done via user.displayName
in my FirebaseSimpleLogin instance. When I try getting their email with user.email
, it returns undefined
. I have done the same thing with Google+ and it works just fine, no undefineds returned. Here is my code:
var chatRef = new Firebase('https://******.firebaseio.');
//No, i didn't actually put this firebase name in my code =P
var auth = new FirebaseSimpleLogin(chatRef, function(error, user) {
if (error) {
// an error occurred while attempting login
console.log(error);
alert('An error occurred while trying to log you in.' + error);
} else if (user) {
// user authenticated with Firebase
console.log('Name: ' + user.displayName + ', email: ' + user.email);
//With google, 'Name: John Doe, email: [email protected]' is returned
//With facebook, 'Name: John Doe, email: undefined' is returned
} else {
// user is logged out
}
});
function google() {
auth.login('google', {
rememberMe: true
});
}
function facebook() {
auth.login('facebook', {
rememberMe: true,
scope: 'email'
});
}
So, my question is, how can i get the user's email address with Facebook Firebase Simple Login? Thank you all in advanced.
Share Improve this question asked Jun 18, 2014 at 0:39 whirishwhirish 4705 silver badges18 bronze badges 1-
In addition to what I posted in my answer, if you add to the code:
else if (user) { console.log(user);}
you'll know what properties exist on the user object as you have it set up currently. Additional permission might be required - see below. Thank you. – LexJacobs Commented Jun 18, 2014 at 1:00
1 Answer
Reset to default 6Before you start, the best way to see what properties already exist on the user object is to add a console log to your existing auth check.
Using:
else if (user){
console.log(user);
}
you'll know what properties exist on the user object as you have it set up currently. Additional permission might be required - see below.
Per facebook dev docs, permissions are strings that are passed along with a login request or an API call. Here are two examples of permissions:
- email: Access to a person's primary email address.
- user_likes: Access to the list of things a person likes.
For example, if you add the login button to a web app and ask for email and user_likes via the scope parameter, a person would be prompted with this dialog when logging in for the first time:
And per firebase Docs
Here is an example where the session will be stored for 30 days (due to the 'remember me' setting), and we also request some extended permissions for email and user_likes:
auth.login('facebook', {
rememberMe: true,
scope: 'email,user_likes'
});
So, unless you have added the additional permissions in the auth.login parameters, you will not be able to access the user's primary email address.
本文标签: javascriptGet email with Facebook Firebase Simple LoginStack Overflow
版权声明:本文标题:javascript - Get email with Facebook Firebase Simple Login - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745480957a2660169.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论