googlesamples / google-services

A collection of quickstart samples demonstrating the Google APIs for Android and iOS
https://developers.google.com
Apache License 2.0
3.07k stars 2.53k forks source link

ERROR 10 #487

Open hamidbayati opened 3 years ago

hamidbayati commented 3 years ago

I use google Sign-in OAuth2 for my android app, and config step by step project like the google doc, and create Client id for android(release and debug version) and web application and everything is okay. But sometimes it does not work and somtimes it works good, when it does not work i get error code 10, and I can't understand what is wrong.

my code:

    private fun checkGoogle(){
        val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
           .requestIdToken(getString(R.string.server_client_id))
            .requestEmail().build()
         mGoogleSignInClient = GoogleSignIn.getClient(getParentActivity(), gso)
        val account = GoogleSignIn.getLastSignedInAccount(requireContext())
        if (account != null) {
            mGoogleSignInClient?.signOut()
        }
    }
googleTextView.setOnClickListener {
            startActivityForResult(mGoogleSignInClient?.signInIntent, RC_SIGN_IN)
        }
 override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == RC_SIGN_IN) {
                try {
                    val task = GoogleSignIn.getSignedInAccountFromIntent(data)
                    val account = task.getResult(ApiException::class.java)
                    googleInfo["idToken"] = account?.idToken ?: ""
                    viewModel.checkGoogleAccount(account?.idToken as String)
                } catch (e: ApiException) {
                    view?.let {
                        notify(
                            it,
                            AndroidUtilities.getString(R.string.googleConnectionFailed)
                        )
                    }
                }
            }
        }
    }

I use implementation("com.google.android.gms:play-services-auth:15.0.0")

Screenshot from 2020-12-08 00-15-49

jyashi commented 1 year ago

Did you find a solution to this? Same issue here