Исключение Google Access с Firebase - PullRequest
0 голосов
/ 20 января 2020

Я занимаюсь разработкой приложения Android с доступом к Google через Firebase. У меня есть Activity для обработки входа в систему, и она работает со вчерашнего дня: после проверки входа и выхода из системы я больше не проверял их. Теперь я нажал кнопку выхода из системы и получил следующее исключение при попытке войти в систему:

W: com.google.android.gms.common.api.ApiException: 10: 
com.google.android.gms.common.api.ApiException: 10: 
    at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(com.google.android.gms:play-services-base@@17.1.0:4)
    at com.google.android.gms.auth.api.signin.GoogleSignIn.getSignedInAccountFromIntent(Unknown Source:8)
    at com.example.locker.LoginActivity.onActivityResult(LoginActivity.java:92)
    at android.app.Activity.dispatchActivityResult(Activity.java:8110)
    at android.app.ActivityThread.deliverResults(ActivityThread.java:4838)
    at android.app.ActivityThread.handleSendResult(ActivityThread.java:4886)
    at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7356)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

Я попытался снова поставить отпечаток sha1 с помощью firebase и Android Studio, а также удалить и повторно вставьте мою учетную запись Google, но ничего не изменится.

Вот моя активность:

public class LoginActivity extends Activity implements View.OnClickListener{
    private static final String TAG = LoginActivity.class.getSimpleName();

    private static final int RC_SIGN_IN = 9001;
    private Button login_button;
    private ProgressBar progress_login;
    private ImageView welcome_logo;

    private FirebaseAuth mAuth;
    private FirebaseUser user;
    private GoogleSignInClient mGoogleSignInClient;

    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Intent intent = getIntent();

        login_button = findViewById(R.id.login_button);
        progress_login = findViewById(R.id.progress_login);
        welcome_logo = findViewById(R.id.welcome_logo);

        login_button.setOnClickListener(this);

        // Initialize Firebase Auth
        mAuth = FirebaseAuth.getInstance();

        // Configure Google Sign In
        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestIdToken(getString(R.string.default_web_client_id))
                .requestEmail()
                .build();

        // Build a GoogleSignInClient with the options specified by gso.
        mGoogleSignInClient = GoogleSignIn.getClient(this, gso);

        // Initialize Firebase Auth
        mAuth = FirebaseAuth.getInstance();

        // Logout check
        if (intent.hasExtra("logout")
                && intent.getBooleanExtra("logout", true)) signOut();
    }

    @Override
    public void onStart() {
        super.onStart();
        // Check if user is signed in (non-null) and update UI accordingly.
        user = mAuth.getCurrentUser();
        updateUI();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
        if (requestCode == RC_SIGN_IN) {
            Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
            try {
                // Google Sign In was successful, authenticate with Firebase
                GoogleSignInAccount account = task.getResult(ApiException.class);
                firebaseAuthWithGoogle(account);
            } catch (ApiException e) {
                // Google Sign In failed, update UI appropriately
                Log.w(TAG, e.toString(), e);
                // [START_EXCLUDE]
                user = null;
                updateUI();
                // [END_EXCLUDE]
            }
        }
    }

    private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
        Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());

        AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
        mAuth.signInWithCredential(credential)
                .addOnCompleteListener(this, task -> {
                    if (task.isSuccessful()) {
                        // Sign in success, update UI with the signed-in user's information
                        Log.d(TAG, "signInWithCredential:success");
                        user = mAuth.getCurrentUser();
                        updateUI();
                    } else {
                        // If sign in fails, display a message to the user.
                        Log.w(TAG, "signInWithCredential:failure", task.getException());
                        user = null;
                        updateUI();
                    }
                });
    }

    private void signIn() {
        Intent signInIntent = mGoogleSignInClient.getSignInIntent();
        startActivityForResult(signInIntent, RC_SIGN_IN);
    }

    public void signOut() {
        // Firebase sign out
        mAuth.signOut();
        user = null;

        // Google sign out
        mGoogleSignInClient.signOut().addOnCompleteListener(this,
                task -> updateUI());
    }


    private void revokeAccess() {
        // Firebase sign out
        mAuth.signOut();
        user = null;

        // Google revoke access
        mGoogleSignInClient.revokeAccess().addOnCompleteListener(this,
                task -> updateUI());
    }

    private void updateUI() {
        if (user != null) {
            Intent intent = new Intent(LoginActivity.this, LockerActivity.class);
            //Passing user data
            intent.putExtra("email", user.getEmail());
            intent.putExtra("name", user.getDisplayName());
            intent.putExtra("userID", user.getUid());

            startActivity(intent);
        }
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.login_button) {
            progress_login.setVisibility(View.VISIBLE);
            signIn();
            progress_login.setVisibility(View.INVISIBLE);
        }
    }
}

И мой выход из системы (где я больше не могу go, очевидно) во второй операции:

@Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.logout_button) {
            Intent intent = new Intent(LockerActivity.this, LoginActivity.class);
            intent.putExtra("logout", true);
            startActivity(intent);
        }
    }

Я действительно не знаю, как исправить эту ошибку, тем более что я не редактировал этот код с тех пор, как написал и протестировал его.

Спасибо!

...