一些细节:
在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-In和the 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一起使用,在我们的应用程序的先前版本中取得了不同的成功) 。这是console.developers.google.com中与我合并的项目:
来自合并的firebase项目的一些图像:
我确实下载了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密钥哈希后,它才开始在我自己的手机上工作。
expo fetch:android:hashes]获得的键/凭据>。
[另外,不要百分百确定这一点,但我认为其他人(在IOS上使用google登录功能,但在Android上无法运行)也可以通过运行“ expo build:android -t apk“
而不是简单的” expo build:android“。我认为,这样做是为了替换google-services.json is n't中的内容,但可能以阻止google缩小应用程序大小为代价。但是,如果同时测试这两个[[和替换哈希/指纹,那么这两个操作可能会相互抵消。如果有要求,我可以尝试更好地解释/更详细。