Я пытаюсь разработать приложение с аутентификацией Google с использованием Firebase в kotlin. Когда я нажимал на кнопку, он отображал доступную учетную запись, но нажимал на любую учетную запись, на которой отображалось всплывающее сообщение. Не удалось войти в систему.
Это код, который я использую
class login : AppCompatActivity() {
val RC_SIGN_IN: Int = 1
lateinit var mGoogleSignInClient: GoogleSignInClient
lateinit var mGoogleSignInOptions: GoogleSignInOptions
private lateinit var firebaseAuth: FirebaseAuth
// Configure Google Sign In
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
firebaseAuth = FirebaseAuth.getInstance()
configureGoogleSignIn()
setupUI()
}
private fun configureGoogleSignIn() {
mGoogleSignInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build()
mGoogleSignInClient = GoogleSignIn.getClient(this, mGoogleSignInOptions)
}
private fun setupUI() {
google_button.setOnClickListener {
signIn()
}
}
private fun signIn() {
val signInIntent: Intent = mGoogleSignInClient.signInIntent
startActivityForResult(signInIntent, RC_SIGN_IN)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == RC_SIGN_IN) {
val task: Task<GoogleSignInAccount> = GoogleSignIn.getSignedInAccountFromIntent(data)
try {
val account = task.getResult(ApiException::class.java)
if (account != null) {
firebaseAuthWithGoogle(account)
}
} catch (e: ApiException) {
Toast.makeText(this, "Google sign in failed:(", Toast.LENGTH_LONG).show()
}
}
}
private fun firebaseAuthWithGoogle(acct: GoogleSignInAccount) {
val credential = GoogleAuthProvider.getCredential(acct.idToken, null)
firebaseAuth.signInWithCredential(credential).addOnCompleteListener {
if (it.isSuccessful) {
val intent = Intent(applicationContext, MainActivity::class.java)
startActivity(intent)
finish()
} else {
Toast.makeText(this, "Google sign in failed:(", Toast.LENGTH_LONG).show()
}
}
}
override fun onStart() {
super.onStart()
val user = FirebaseAuth.getInstance().currentUser
if (user != null) {
val intent = Intent(applicationContext, MainActivity::class.java)
startActivity(intent)
finish()
}
}
companion object {
fun getLaunchIntent(from: Context) = Intent(from, login::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
}
}
}
Но отображается Ошибка входа в Google: просим помочь, я дал inte rnet разрешение
Я также установил службу Google в intellij