簡體   English   中英

從 Play 商店安裝應用程序后嘗試使用 google 登錄時,出現“使用 Google 進行身份驗證時出錯:未知”異常。 查看詳細信息

[英]Getting 'Error authenticating with Google: unknown' exception when trying to signin with google after installing app from play store. See details

我在我的應用程序中集成了 Google 登錄。

當我通過直接從 android studio 安裝來測試我的設備上的應用程序時,Google 登錄工作正常。

但是,在發布我的應用程序的 Beta 版並從 Play 商店安裝它之后,當我嘗試使用 Google 登錄時,出現以下錯誤:“ Error authenticating with Google: unknown ”。

這是我的代碼:

    // in onCreate()

    googleLoginButton = (SignInButton) findViewById(R.id.google_login_button);
            googleLoginButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                        mGoogleLoginClicked = true;
                        if (!mGoogleApiClient.isConnecting()) {
                            if (mGoogleConnectionResult != null) {
                                resolveSignInError();
                            } else if (mGoogleApiClient.isConnected()) {
                                getGoogleOAuthTokenAndLogin();
                            } else {
                        /* connect API now */
                                Log.d(TAG, "Trying to connect to Google API");
                                mGoogleApiClient.connect();
                            }
                        }

                }
            });
            /* Setup the Google API object to allow Google+ logins */
            mGoogleApiClient = new GoogleApiClient.Builder(this)
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .addApi(Plus.API)
                    .addScope(Plus.SCOPE_PLUS_LOGIN)
                    .addScope(Plus.SCOPE_PLUS_PROFILE)
                    .addScope(new Scope("https://www.googleapis.com/auth/userinfo.email"))
                    .build();


    // in onActivityResult()

    @Override
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            Map<String, String> options = new HashMap<String, String>();
            if (requestCode == RC_GOOGLE_LOGIN) {
                /* This was a request by the Google API */
                if (resultCode != RESULT_OK) {
                    mGoogleLoginClicked = false;
                }
                mGoogleIntentInProgress = false;
                if (!mGoogleApiClient.isConnecting()) {
                    mGoogleApiClient.connect();
                }
            } else {
                /* Otherwise, it's probably the request by the Facebook login button, keep track of the session */
                mFacebookCallbackManager.onActivityResult(requestCode, resultCode, data);
            }
        }



    // rest of the code:

    private void resolveSignInError() {
            if (mGoogleConnectionResult.hasResolution()) {
                try {
                    mGoogleIntentInProgress = true;
                    mGoogleConnectionResult.startResolutionForResult(this, RC_GOOGLE_LOGIN);
                } catch (IntentSender.SendIntentException e) {
                    // The intent was canceled before it was sent.  Return to the default
                    // state and attempt to connect to get an updated ConnectionResult.
                    mGoogleIntentInProgress = false;
                    mGoogleApiClient.connect();
                }
            }
        }

        private void getGoogleOAuthTokenAndLogin() {
            /* Get OAuth token in Background */
            AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {
                String errorMessage = null;

                @Override
                protected String doInBackground(Void... params) {
                    String token = null;

                    try {
                        String scope = "oauth2:https://www.googleapis.com/auth/plus.login";
  // logcat showing error on this line -> token = GoogleAuthUtil.getToken(SignupScreenActivity.this, Plus.AccountApi.getAccountName(mGoogleApiClient), scope);
                    } catch (IOException transientEx) {
                        /* Network or server error */
                        Log.e(TAG, "Error authenticating with Google: " + transientEx);
                        errorMessage = "Network error: " + transientEx.getMessage();
                    } catch (UserRecoverableAuthException e) {
                        Log.w(TAG, "Recoverable Google OAuth error: " + e.toString());
                        /* We probably need to ask for permissions, so start the intent if there is none pending */
                        if (!mGoogleIntentInProgress) {
                            mGoogleIntentInProgress = true;
                            Intent recover = e.getIntent();
                            startActivityForResult(recover, RC_GOOGLE_LOGIN);
                        }
                    } catch (GoogleAuthException authEx) {
                        /* The call is not ever expected to succeed assuming you have already verified that
                         * Google Play services is installed. */
                        Log.e(TAG, "Error authenticating with Google: " + authEx.getMessage(), authEx);
                        errorMessage = "Error authenticating with Google: " + authEx.getMessage();
                    }
                    return token;
                }

                @Override
                protected void onPostExecute(String token) {
                    mGoogleLoginClicked = false;
                    if (token != null) {
                        progressDialog = ProgressDialog.show(SignupScreenActivity.this, "",
                                "Logging in with google...", true);
                        progressDialog.show();
                        /* Successfully got OAuth token, now login with Google */
                        ref.authWithOAuthToken("google", token, new Firebase.AuthResultHandler() {
                            @Override
                            public void onAuthenticated(AuthData authData) {
                                Intent mainActivityIntent = new Intent(SignupScreenActivity.this, MainActivity.class);
                                mainActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                mainActivityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                                startActivity(mainActivityIntent);
                                progressDialog.hide();
                            }

                            @Override
                            public void onAuthenticationError(FirebaseError firebaseError) {
                                Toast.makeText(getBaseContext(), firebaseError.getMessage(), Toast.LENGTH_LONG).show();
                                progressDialog.hide();
                            }
                        });
                    } else if (errorMessage != null) {
                        Toast.makeText(getBaseContext(), errorMessage, Toast.LENGTH_LONG).show();
                    }
                }
            };
            task.execute();
        }

        @Override
        public void onConnected(final Bundle bundle) {
            /* Connected with Google API, use this to authenticate with Firebase */
            getGoogleOAuthTokenAndLogin();
        }


        @Override
        public void onConnectionFailed(ConnectionResult result) {
            if (!mGoogleIntentInProgress) {
                /* Store the ConnectionResult so that we can use it later when the user clicks on the Google+ login button */
                mGoogleConnectionResult = result;

                if (mGoogleLoginClicked) {
                    /* The user has already clicked login so we attempt to resolve all errors until the user is signed in,
                     * or they cancel. */
                    resolveSignInError();
                } else {
                    Log.e(TAG, result.toString());
                }
            }
        }

        @Override
        public void onConnectionSuspended(int i) {
            // ignore
        }

logcat詳細信息:

Error authenticating with Google: Unknown
com.google.android.gms.auth.GoogleAuthException: Unknown
     at com.google.android.gms.auth.GoogleAuthUtil$1.zzam(Unknown Source)
     at com.google.android.gms.auth.GoogleAuthUtil$1.zzan(Unknown Source)
     at com.google.android.gms.auth.GoogleAuthUtil.zza(Unknown Source)
     at com.google.android.gms.auth.GoogleAuthUtil.zza(Unknown Source)
     at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
     at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
     at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
     at com.abc.xyz.SignupScreenActivity$10.doInBackground(SignupScreenActivity.java:480)
     at com.abc.xyz.SignupScreenActivity$10.doInBackground(SignupScreenActivity.java:471)
     at android.os.AsyncTask$2.call(AsyncTask.java:288)
     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
     at java.lang.Thread.run(Thread.java:818)

這是build.gradle

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.abc.xyz"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 4
        versionName "0.3"
        multiDexEnabled true
    }

    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
        exclude 'META-INF/NOTICE'
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.android.support:design:23.2.1'
    compile 'com.android.support:cardview-v7:23.2.1'
    compile 'com.firebase:firebase-client-android:2.3.1'
    compile 'com.facebook.android:facebook-android-sdk:4.1.0'
    compile 'com.google.android.gms:play-services-maps:8.3.0'
    compile 'com.google.android.gms:play-services-plus:8.3.0'
    compile 'com.android.support:support-v4:23.2.1'
}

我不知道這里出了什么問題!

請告訴我。

確保您已使用 SHA1 指紋的發布版本創建了新的客戶端 ID。

打開終端(在Unix 中,在MAC 中),(在Windows 中為cmd )並cd到此(您的 java)路徑:

C:\Program Files\Java\jdk1.6.0_43\bin>

運行此命令:

keytool -list -v -keystore "your keystore path" -alias "keystore alias name" -storepass "keystore password" -keypass "keystore password"

據我所知,為了生成 Google API 的訪問密鑰,您必須提供一些有關您的應用的數據,包括用於簽署您的 APK 的密鑰。 正如 Baijrao Shinde 在他的回答中指出的那樣,您應該仔細檢查您是否有兩個不同的客戶端 ID,用於在調試模式(直接從 Android Studio 使用調試密鑰唱 APK)和生產模式(從 Android Studio 安裝)下運行您的應用程序Google Play 使用生產密鑰對 APK 進行簽名)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM