我在安卓工作室中使用“生成签名捆绑包”生成了我的密钥库。
我用keytool得到了我的SHA1和SHA256
我的应用程序尚未在Google Play中发布。
我正在登录:
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
...
println(result.resultCode)
val signInResult = result.data?.let { Auth.GoogleSignInApi.getSignInResultFromIntent(it) }
println(signInResult?.status)
...
Logcat中的结果是:
0
Status{statusCode=DEVELOPER_ERROR, resolution=null}
主要活动
package io.ionic.brooksfield
...
lateinit var googleSignInClient: GoogleSignInClient
private lateinit var firebaseAuth: FirebaseAuth
...
override fun onCreate(savedInstanceState: Bundle?) {
...
val googleSignInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail().build()
googleSignInClient = GoogleSignIn.getClient(this@MainActivity, googleSignInOptions)
val button = findViewById<Button>(R.id.btnLogin)
button.setOnClickListener {
val intent: Intent = googleSignInClient.signInIntent
resultLauncher.launch(intent)
}
FirebaseApp.initializeApp(this);
firebaseAuth = FirebaseAuth.getInstance()
val firebaseUser: FirebaseUser? = firebaseAuth.currentUser
if (firebaseUser != null) {
println(firebaseUser.displayName)
}
}
var resultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) {
val signInAccountTask: Task<GoogleSignInAccount> = GoogleSignIn.getSignedInAccountFromIntent(result.data)
val data: Intent? = result.data
val txt = findViewById<TextView>(R.id.txtResult)
txt.text = data.toString()
}
}
建筑.gradle
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.3.15'
}
}
plugins {
id 'com.android.application' version '8.0.1' apply false
id 'com.android.library' version '8.0.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
id 'com.google.gms.google-services' version '4.3.15' apply false
}
应用程序/build.gradle
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.gms.google-services'
}
android {
namespace 'io.ionic.brooksfield'
compileSdk 33
defaultConfig {
applicationId "io.ionic.brooksfield"
minSdk 28
targetSdk 33
...
}
...
}
dependencies {
implementation platform('androidx.compose:compose-bom:2022.10.00')
implementation 'com.google.gms:google-services:4.3.15'
implementation platform('com.google.firebase:firebase-bom:32.0.0')
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.android.gms:play-services-auth:20.5.0'
androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00')
}
谷歌服务.json
{
"project_info": {
"project_number": "169490533010",
"project_id": "fusapp-2cbfb",
"storage_bucket": "fusapp-2bcfb.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:169480533010:android:20b1a56e5bb5b57a89764b",
"android_client_info": {
"package_name": "io.ionic.brooksfield"
}
},
"oauth_client": [
{
"client_id": "169480533010-5ui..57ae.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "io.ionic.brooksfield",
"certificate_hash": "6332f3f57f44c8da45cebbd3d1cea2872a9ae5a4"
}
},
{
"client_id": "169480533010-f4..f0.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSxBcMnITszPIucOZRe4qqPRQdUhPyDsWawY"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "169480533010-f4...f0.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
Firebase io.ionic.brooksfield控制台:
谷歌安卓应用控制台:
谷歌网络应用控制台:
我尝试使用旧方法,得到状态代码10:
val btnLogin = findViewById<Button>(R.id.btnLogin)
btnLogin.setOnClickListener {
val intent: Intent = googleSignInClient.signInIntent
startActivityForResult(intent, 11)
}
...}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == 11) {
val task = GoogleSignIn.getSignedInAccountFromIntent(data)
handleSignInResult(task)
}
}
private fun handleSignInResult(completedTask: Task<GoogleSignInAccount>) {
try {
val account = completedTask.getResult(ApiException::class.java)
println(account.displayName)
println(account.email)
} catch (e: ApiException) {
println("signInResult:failed code=" + e.statusCode)
}
}
我尝试了其他解决方案,例如,使用Web服务器Id:
val googleSignInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken("169480533010-f4..f0.apps.googleusercontent.com")
.requestEmail().build()