Google/Firebase iOS 的身份验证没有 displayName 或 photoURL
Google/Firebase Authentication no displayName or photoURL for iOS
我正在使用 Ionic2 和 GooglePlus Authentication。
我可以登录,它会按预期在 Firebase Authentication
列表中创建一个具有 uid
的用户。
当我这样做时:
GooglePlus.login({
'webClientId': webClientId,
'offline': true
}).then(googleData => {
其中 webClientId
与下面 iOS Credential
中的 Client ID
匹配。
问题:
但是,对于 iOS
,googleData
确实包含 emailAddress
和 uid
,但 displayName
和 photoURL
是 null
.
更多信息:
我确实有一个 iOS Credential
设置 Bundle ID
匹配 config.xml
中的 widget id
:
config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.ionicframework.XXXXXXX" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>theWhoZoo</name>
而且它还有 REVERSED_CLIENT_ID
匹配上面的 iOS URL scheme
。
<plugin name="cordova-plugin-googleplus" spec="~5.1.1">
<variable name="REVERSED_CLIENT_ID" value="com.googleusercontent.apps.XXXXXX" />
</plugin>
我还为我的项目创建了一个 Firebase App
,它也有匹配的 Bundle ID
(不确定这是否有任何效果):
此外,我不确定这是否有任何区别,但我在此处将 iOS
的 CLIENT_ID
添加到 Google Firebase 身份验证:
问题
为 iOS
设置此设置时我是否遗漏了任何步骤或做错了什么?
这应该添加获取配置文件数据所需的范围:
window.plugins.googleplus.login({
'scopes': 'https://www.googleapis.com/auth/plus.me',
// continue below...
详见官方documentation and the plugin documentation
范围描述为here。
这是我的代码,它与 IOS 配合使用效果很好。
代码
private nativeGoogleLogin(): Promise<firebase.User> {
return new Promise(async (resolve, reject) => {
const SCOPES = 'https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/gmail.send https://www.googleapis.com/auth/plus.me';
await this.gPlus.login({
'webClientId': 'XXXXXXXX.apps.googleusercontent.com',
'offline': true,
'scopes': SCOPES
}).then(res => {
const googleCredential = firebase.auth.GoogleAuthProvider.credential(res.idToken , res.access_token);
this.afAuth.auth.signInWithCredential(googleCredential).then(odata => {
resolve(odata);
}).catch(err => {
reject(err);
});
}).catch(err => {
reject(err);
});
});
}
如何获取 displayName 名称
async onGoogleLogin() {
await this.goAuth.googleLogin().then(res => {
alert(JSON.stringify(res));
alert(res.providerData[0].displayName);
}).catch(err => {
console.log(err);
});
}
res.providerData[0].displayName
Note : Uninstall you app in emulator and clean your build folder before using this
code.
我正在使用 Ionic2 和 GooglePlus Authentication。
我可以登录,它会按预期在 Firebase Authentication
列表中创建一个具有 uid
的用户。
当我这样做时:
GooglePlus.login({
'webClientId': webClientId,
'offline': true
}).then(googleData => {
其中 webClientId
与下面 iOS Credential
中的 Client ID
匹配。
问题:
但是,对于 iOS
,googleData
确实包含 emailAddress
和 uid
,但 displayName
和 photoURL
是 null
.
更多信息:
我确实有一个 iOS Credential
设置 Bundle ID
匹配 config.xml
中的 widget id
:
config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.ionicframework.XXXXXXX" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>theWhoZoo</name>
而且它还有 REVERSED_CLIENT_ID
匹配上面的 iOS URL scheme
。
<plugin name="cordova-plugin-googleplus" spec="~5.1.1">
<variable name="REVERSED_CLIENT_ID" value="com.googleusercontent.apps.XXXXXX" />
</plugin>
我还为我的项目创建了一个 Firebase App
,它也有匹配的 Bundle ID
(不确定这是否有任何效果):
此外,我不确定这是否有任何区别,但我在此处将 iOS
的 CLIENT_ID
添加到 Google Firebase 身份验证:
问题
为 iOS
设置此设置时我是否遗漏了任何步骤或做错了什么?
这应该添加获取配置文件数据所需的范围:
window.plugins.googleplus.login({
'scopes': 'https://www.googleapis.com/auth/plus.me',
// continue below...
详见官方documentation and the plugin documentation
范围描述为here。
这是我的代码,它与 IOS 配合使用效果很好。
代码
private nativeGoogleLogin(): Promise<firebase.User> {
return new Promise(async (resolve, reject) => {
const SCOPES = 'https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/gmail.send https://www.googleapis.com/auth/plus.me';
await this.gPlus.login({
'webClientId': 'XXXXXXXX.apps.googleusercontent.com',
'offline': true,
'scopes': SCOPES
}).then(res => {
const googleCredential = firebase.auth.GoogleAuthProvider.credential(res.idToken , res.access_token);
this.afAuth.auth.signInWithCredential(googleCredential).then(odata => {
resolve(odata);
}).catch(err => {
reject(err);
});
}).catch(err => {
reject(err);
});
});
}
如何获取 displayName 名称
async onGoogleLogin() {
await this.goAuth.googleLogin().then(res => {
alert(JSON.stringify(res));
alert(res.providerData[0].displayName);
}).catch(err => {
console.log(err);
});
}
res.providerData[0].displayName
Note : Uninstall you app in emulator and clean your build folder before using this code.