Firebase网络在Google和Facebook上获取提供商数据(性别和生日)

时间:2017-09-25 13:21:55

标签: javascript facebook firebase firebase-authentication google-login

Herer是我的Google部分

var provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().languageCode = 'zh-TW';
provider.addScope('profile');
provider.addScope('https://www.googleapis.com/auth/userinfo.profile');
provider.addScope('https://www.googleapis.com/auth/userinfo.email');
provider.addScope('https://www.googleapis.com/auth/plus.login');
provider.addScope('https://www.googleapis.com/auth/plus.me');
provider.addScope('https://www.googleapis.com/auth/user.birthday.read');
provider.addScope('email');
firebase.auth().signInWithPopup(provider).then(function(result) {
    console.log(result.user)
}).catch(function(error) {
    app.message.register = error.message;
});

Herer是我的Facebook部分

 var provider = new firebase.auth.FacebookAuthProvider();
    provider.addScope('user_birthday');
    firebase.auth().languageCode = 'zh-TW';
    firebase.auth().signInWithPopup(provider).then(function(result) {

      console.log(result.user)

    }).catch(function(error) {

    });

这两部分未获得console.log(result.user)中的性别和生日,是否缺少某些设置?或者有错误的部分?有什么想法吗?

1 个答案:

答案 0 :(得分:1)

返回的访问令牌result.credential.accessToken将提供对这些附加范围的访问权限。您需要使用该访问令牌查询Google / Facebook API以获取此数据(特定于其他请求的范围)。顺便说一下,现在返回一些特定于IdP的额外用户信息。检查result.additionalUserInfo.profile的内容。

相关问题