【问题标题】:Google/Firebase Authentication no displayName or photoURL for iOSGoogle/Firebase 身份验证没有适用于 iOS 的 displayName 或 photoURL
【发布时间】:2017-08-01 20:59:45
【问题描述】:

我正在使用 Ionic2 和 GooglePlus Authentication

我可以登录,它会按预期在Firebase Authentication 列表中创建一个具有uid 的用户。

当我这样做时:

        GooglePlus.login({
            'webClientId': webClientId,
            'offline': true
        }).then(googleData => {

webClientId 与下面iOS Credential 中的Client ID 匹配。

问题:

但是,对于iOSgoogleData 确实包含emailAddressuid,但displayNamephotoURLnull

更多信息:

我确实有一个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>

它还有与上面的iOS URL scheme 匹配的REVERSED_CLIENT_ID

<plugin name="cordova-plugin-googleplus" spec="~5.1.1">
    <variable name="REVERSED_CLIENT_ID" value="com.googleusercontent.apps.XXXXXX" />
</plugin>

我还为我的项目创建了一个Firebase App,它也具有匹配的Bundle ID(不确定这是否有任何影响):

另外,我不确定这是否有任何区别,但我在此处将 CLIENT_ID for iOS 添加到 Google Firebase 身份验证中:

问题

在为iOS 进行设置时,我是否遗漏了任何步骤或做错了什么?

【问题讨论】:

  • 我需要安装 Cocoa Pods 吗?我希望我的应用尽可能简单轻量。

标签: angular firebase ionic2 google-plus firebase-authentication


【解决方案1】:

这是我的代码,它适用于 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

注意:在模拟器中卸载你的应用程序并在使用它之前清理你的构建文件夹 代码。

【讨论】:

    【解决方案2】:

    这应该添加获取配置文件数据所需的范围:

    window.plugins.googleplus.login({
      'scopes': 'https://www.googleapis.com/auth/plus.me',
      // continue below...
    

    详见官方documentation和插件documentation

    范围描述为here

    【讨论】:

    • 谢谢!!!你解决了我的问题。我整个周末都在努力解决这个问题。
    • 发生了我无法解释的最奇怪的事情。我按照您的建议进行了更改,然后在Xcode 中构建了项目,它返回了displayNamephotoUrl。所以我认为它是固定的。但是,然后我做了一个ionic build ios,然后在Xcode 中再次构建它,现在它不返回displayNamephotoUrl
    • 请尝试进行干净的构建。见here
    • 谢谢,我尝试了ionic platform remove ios,然后是ionic platform add ios,然后是ionic build ios。然后在 Xcode 中运行项目,得到以下信息:keychain error
    • Ionic 似乎有些废话。见12
    猜你喜欢
    • 2018-03-10
    • 2021-11-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-17
    • 1970-01-01
    • 2016-09-26
    • 2016-10-22
    • 2021-08-23
    相关资源
    最近更新 更多