我正在使用Parse,我正在尝试创建一个简单的Facebook登录。
我的FB初始化如下:
window.fbAsyncInit = function() {
Parse.FacebookUtils.init({ // this line replaces FB.init({
appId : 'xxxxxxxxxxxxxx', // Facebook App ID
status : true, // check Facebook Login status
cookie : true, // enable cookies to allow Parse to access the session
xfbml : true, // initialize Facebook social plugins on the page
version : 'v2.3' // point to the latest Facebook Graph API version
});
};
我的FB登录功能如下:
Parse.FacebookUtils.logIn('email', {
success: function(user) {
if (!user.existed()) {
alert("User signed up and logged in through Facebook!");
} else {
alert("User logged in through Facebook!");
}
},
error: function(user, error) {
console.log(error);
}
});
流程很有效,因为我可以看到在Parse核心视图(用户表)中创建(首次登录时)用户,我可以看到Parse.User.current()是FB用户。
问题是,我找不到用户的电子邮件......
我试过了:
Parse.User.current().getEmail(); //undefined
FB.api('/me', function(me) { console.log(me) }); //prints an object with 'name' and 'id' fields only
没有任何作用....
另外,我尝试将null /'email'/'public_profile,email'作为第一个FB登录参数,但没有成功... :(
有什么想法吗?
谢谢!
答案 0 :(得分:3)
FB.api('/me?fields=name,email', function(me) { console.log(me) });
它被称为“声明字段”:https://developers.facebook.com/docs/apps/changelog#v2_4
如果这不起作用,那么登录可能有问题。确保要求您提供电子邮件权限。