class GoogleAuthClient(private val context: Context) {
private val credentialManager = CredentialManager.create(context)
private val firebaseAuth = FirebaseAuth.getInstance()
fun isSingedIn(): Boolean {
if (firebaseAuth.currentUser != null) {
return true
}
return false
}
suspend fun signIn(): Boolean {
if (isSingedIn()) {
return true
}
try {
val result = buildCredentialRequest()
val signInResult = handleSingIn(result)
return signInResult
} catch (e: Exception) {
e.printStackTrace()
if (e is CancellationException) throw e
return false
}
}
private suspend fun buildCredentialRequest(): GetCredentialResponse {
val request = GetCredentialRequest.Builder()
.addCredentialOption(
GetGoogleIdOption.Builder()
.setFilterByAuthorizedAccounts(false)
.setServerClientId(
""
)
.setAutoSelectEnabled(true)
.build()
)
.build()
return credentialManager.getCredential(
context = context,
request = request
)
}
}
Привет, я пытаюсь создать код входа в Google с помощью Credential Manager API, но не могу устранить ошибку!
Я дублирую проверил SHA-1, идентификатор клиента, google-services.json, но не могу устранить ошибку.
Ошибка произошла из этого блока кода:
return credentialManager.getCredential(
context = context,
request = request,
)
Журнал ошибок:
2024-11-20 15:10:07.645 29668-29684 CredManProvService com.example.cherryboy I GetCredentialResponse error returned from framework
2024-11-20 15:10:07.648 29668-29668 System.err com.example.cherryboy W androidx.credentials.exceptions.NoCredentialException: No credentials available
2024-11-20 15:10:07.649 29668-29668 System.err com.example.cherryboy W at androidx.credentials.internal.ConversionUtilsKt.toJetpackGetException(ConversionUtils.kt:82)
2024-11-20 15:10:07.649 29668-29668 System.err com.example.cherryboy W at
Подробнее здесь: https://stackoverflow.com/questions/792 ... -available