0
我正在使用Firebase signinwithcredential进行google auth。我首先使用cordovaoath来获取id令牌并使用firebase进行签名。我在我的代码中特别指出我想获取displayName,但它总是返回null。我想知道任何人都面临同样的问题?在Ionic平台中无法通过firebase3登录获取gmail用户显示名称
this.loginWithGoogle = function loginWithGoogle() {
$cordovaOauth.google("mygoogleclient id here", ["https://www.googleapis.com/auth/calendar","https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile","https://www.googleapis.com/auth/plus.me", "https://www.googleapis.com/auth/plus.login", "https://www.googleapis.com/auth/drive"]).then(function (result) {
// "email", "profile",
console.log("first come here to oath");
console.log("Response Object -> " + JSON.stringify(result));
var unsubscribe = firebase.auth().onAuthStateChanged(function (firebaseUser) {
unsubscribe();
// Check if we are already signed-in Firebase with the correct user.
// Build Firebase credential with the Google ID token.
var credential='';
credential = firebase.auth.GoogleAuthProvider.credential(
result.id_token);
// Sign in with credential from the Google user.
firebase.auth().signInWithCredential(credential).catch(function (error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
});
});
}, function (error) {
console.log("Error -> " + error);
});
};
我的返回结果的撷取画面
的Gmail地址是在你的屏幕截图和验证。有什么问题? –
我想要也获得displayName,但是displayName始终为空,即使我专门为profile.Thanks添加了范围! –
有趣:我得到的显示名称,即使没有指定任何额外的范围:'displayName:“Frank van Puffelen”' –