来自库expo-google-signin的GoogleSignIn.signInAsync()在Android上解析为未定义

问题描述 投票:0回答:1

一些细节:

  • 我正在使用expo,更具体地说是expo SDK 35
  • 我正在使用库expo-google-sign-in
  • 该功能似乎可以在IOS上运行,但不能在Android上运行。
  • 这是一个管理型博览会应用程序,不是裸露/弹出的应用程序。

在Android上,当我调用GoogleSignIn.signInAsync()时,对话框出现,并且似乎按预期方式工作,但是该函数返回的承诺解析为undefined

这里是我的代码的简化摘录(我不显示警报和我认为对我的问题不重要的其他内容):

import * as GoogleSignIn from 'expo-google-sign-in'

...

let clientId = *cencored*
// If I understand the documentation correctly this parameter
// isn't really necessary on Android, but I've provided one anyway.
// Actually, I've tried several different ones.

await GoogleSignIn.initAsync({
    clientId,
    scopes: ['profile', 'email']
})

await GoogleSignIn.askForPlayServicesAsync()

const result = await GoogleSignIn.signInAsync()
// ^ dialogue opens and looks normal/working,
// but the variable named "result" ends up being undefined

这是我的app.json(以及一些注释,这些注释当然不包含在实际文件中:]

{
    "expo": {
        "version": "0.0.61",
        "android": {
            "package": "com.toleio.no",
            "googleServicesFile": "./google-services.json",
            // ^ I've also downloaded an actual file of this type from firebase
            "versionCode": 61,
            "config": {
                "googleSignIn": {
                    "apiKey": *cencored*,
                    // ^ If I understand the documentation correctly
                    // this is uneccecary, but I added it just in case.
                    // I created it on https://console.developers.google.com/apis/credentials?project=signlab-prod
                    // and selecting Create credentials -> API key.
                    // I also tried a build where I tried "Web API key"
                    // from console.firebase.google.com.
                    "certificateHash": *cencored*
                    // ^ I don't know what this parameter is for exactly,
                    // and if I understand the documentation correctly it's
                    // irrellevant/unnececcary. But what I put here is the
                    // has that is called "Google Certificate Hash (SHA-1)"
                    // when I do the console command "expo fetch:android:hashes"
                }
            }
        },
        "sdkVersion": "35.0.0",
        "facebookAppId": *cencored*,
        "facebookDisplayName": "Toleio!",
        "facebookScheme": *cencored*,
        "name": "Toleio",
        "description": "Making Sign Language Available for Everyone",
        "slug": "toleio-app-norwegian",
        "privacy": "unlisted",
        "ios": {
            "bundleIdentifier": "com.toleio.no",
            "supportsTablet": true,
            "usesAppleSignIn": true,
            "config": {
                "googleSignIn": {
                    "reservedClientId": : *cencored*
                }
            }
        },
        "scheme": "toleio",
        // ^ I don't properly/fully understand what this parameter does,
        // and don't know if it might be relevant somehow
        "platforms": [
            "ios",
            "android"
        ],
        "orientation": "portrait",
        "icon": "./assets/icon.png",
        "splash": {
            "image": "./assets/iconWithPadding.png",
            "resizeMode": "contain",
            "backgroundColor": "#ffffff"
        },
        "updates": {
            "fallbackToCacheTimeout": 30000
        },
        "assetBundlePatterns": [
            "**/*"
        ],
        "packagerOpts": {
            "assetExts": [
                "ttf",
                "mp4",
                "dae",
                "obj",
                "amf",
                "3mf",
                "3ds",
                "jpg",
                "assimp",
                "fbx",
                "pmd",
                "vmd",
                "ply",
                "stl",
                "vtk",
                "vtp",
                "sea",
                "gltf",
                "bin"
            ]
        }
    },
    "hooks": {
        "postPublish": [
            {
                "file": "sentry-expo/upload-sourcemaps",
                "config": {
                    "organization": "signlab",
                    "project": "toleio-app",
                    "authToken": : *cencored*
                }
            }
        ]
     }
  }

Expo的文章React Native Google Sign-Inthe documentation展示的内容似乎不仅是使用firebase来使expo-google-sign-in工作正常的方式[,而且是[[the的工作方式它有效(或者至少是我在阅读时的解释)。但是,我可能记错了,但我想我记得在使用Firebase进行任何操作之前,能够从IOS上的GoogleSignIn.signInAsync()提取令牌。我对firebase在使expo-google-sign-in工作中应该扮演的确切角色没有很好的了解,并且有点困惑。 (使用firebase可能仅仅是因为它是生成google-services.json文件的最简单方法吗?)

无论如何,我确实尝试使用Firebase。当点击https://console.firebase.google.com/中的“添加项目”时,我选择了一个现有项目(用于与我们的应用程序相对应的网站上的google登录的项目,并且已与expo-google-app-auth一起使用,在我们的应用程序的先前版本中取得了不同的成功) 。enter image description here

这是console.developers.google.com中与我合并的项目:

enter image description here

来自合并的firebase项目的一些图像:

enter image description hereenter image description hereenter image description here

我确实下载了google-services.json文件,并将其添加到我的项目的根目录中。我不了解该文件的内容,但是我发现其中包含了console.developers.google.com-project中的多个客户端ID。

以下警报在Android上对我来说是未定义的(但也许在Android上是正常的,该文档似乎暗示此测试是针对IOS的:]

import { AppAuth } from 'expo-app-auth' const { URLSchemes } = AppAuth alert(URLSchemes)

[作为旁注(可能或可能不相关):在添加Facebook登录名时,我在developers.facebook.com上从“ expo fetch:android:hashes”中添加了“ Facebook Key Hash”。但是,这不能使登录在我的手机上起作用(但是可以在我朋友的电话上起作用)。仅当我从尝试使用Facebook登录名时显示在手机上的错误消息中添加了Facebook密钥哈希后,它才开始在我自己的手机上工作。

    你们中有人立即看到我做错了吗?
  • 我应该做一些步骤,但不提吗?
  • 您是否有建议,如果您是我的话会尝试吗?
  • 您是否有可能使我们更接近解决方案的问题?
  • 我怀疑该库可能存在问题(与我的实现相反),并且该库的文档有误/具有误导性。我在这里更详细地介绍:https://forums.expo.io/t/does-google-authentication-work-on-android-sdk-35/28754。因此,我对反馈/信息也可能对此有所帮助:

      这里有没有人可以确认他们已经通过Google身份验证才能在Android上使用?
  • 这里有人可以确认他们已经通过Google身份验证在expo-SDK 35的Android上运行吗?
  • 这里有人通过Google身份验证可以在该库的Android系统上工作,但使用的是弹出/裸露的应用程序-不是托管应用程序吗?
  • 我已经坚持了一个星期左右,可以说是更多😟任何帮助(无论是解决方案还是指针),将不胜感激! 🙂
  • android react-native expo google-signin google-authentication
    1个回答
    0
    投票
    您可以在以下位置找到关于此的更多信息:Google play console→列表中有问题的应用程序(在我们的案例中为“ com.toleio.no”)→发行管理(在侧栏中)→应用程序签名(在侧栏子菜单中)。在这里,您还可以找到上传应用程序时放在google-services.json中的密钥。对于firebase和/或google developer console中要放入哈希/指纹的与Android相关的键/凭据,请在其中找到找到的键/凭据,而不是通过

    expo fetch:android:hashes]获得的键/凭据>。

    [另外,不要百分百确定这一点,但我认为其他人(在IOS上使用google登录功能,但在Android上无法运行)也可以通过运行“ expo build:android -t apk“

    而不是简单的

    ” expo build:android“。我认为,这样做是为了替换google-services.json is n't中的内容,但可能以阻止google缩小应用程序大小为代价。但是,如果同时测试这两个[[和替换哈希/指纹,那么这两个操作可能会相互抵消。如果有要求,我可以尝试更好地解释/更详细。

    © www.soinside.com 2019 - 2024. All rights reserved.