Android 获得';使用Google进行身份验证时出错:未知';从play store安装应用程序后尝试登录google时出现异常。详见

Android 获得';使用Google进行身份验证时出错:未知';从play store安装应用程序后尝试登录google时出现异常。详见,android,android-studio,google-plus,google-signin,android-googleapiclient,Android,Android Studio,Google Plus,Google Signin,Android Googleapiclient,我已经在我的应用程序中集成了Google signin 当我在我的设备上直接从android studio安装应用程序进行测试时,Google signin运行良好 但是,在发布了我的应用程序的beta版并从play store安装之后,当我尝试使用Google登录时,我遇到了以下错误:“使用Google进行身份验证时出错:未知”” 这是我的密码: // in onCreate() googleLoginButton = (SignInButton) findViewById(

我已经在我的应用程序中集成了Google signin

当我在我的设备上直接从android studio安装应用程序进行测试时,Google signin运行良好

但是,在发布了我的应用程序的beta版并从play store安装之后,当我尝试使用Google登录时,我遇到了以下错误:“
使用Google进行身份验证时出错:未知”

这是我的密码:

    // 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
        }
下面是
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中,(
cmd
Windows中)和
cd
打开到此(您的java)路径:

运行以下命令:

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

就我所记得的,为了生成GoogleAPI的访问密钥,您必须提供一些关于您的应用程序的数据,包括用于签署APK的密钥。正如Baijrao Shinde在他的回答中指出的那样,您应该仔细检查是否有两个不同的客户端ID,用于在调试模式下运行应用程序(直接从Android Studio安装,使用调试键来唱APK)和生产模式(从Google Play安装,使用生产键来签署APK).

请张贴日志details@NatarajanRaman查看编辑后的问题。@Natarajanman嘿,你要的是logcat,我已经把它贴在这里了。现在请回答这个问题。oauth2:@BajiraoShinde什么?请详细说明。我认为这个答案是正确的,但也许更多的信息将有助于OP更好地了解发生了什么。@BajiraoShinde如何获得SHA1指纹的发布版本?@HammadNasir查看我编辑的答案。如果它有效的话就接受它,这样它将对那些遇到这个问题的人有帮助…快乐的编码。这有助于解释吗?这太令人困惑了。如何知道哪个客户端ID用于调试模式,哪个用于生产模式?目前,我只有一个客户ID。
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"