Google登录未响应

时间:2018-09-05 08:32:12

标签: android firebase firebase-authentication

我有两个登录选项,普通登录和google登录。普通登录可以正常工作,但google登录不是。

我点击google登录按钮,我可以看到这些帐户。因此,我单击了该帐户,但是什么也没有发生。而且我也看不到firebase上的用户数据。

我在模拟器或android studio上没有任何错误。我错过了一些东西,但是什么?

我正在关注this tutorial的Google登录方法。

更新错误日志

我终于找到了错误日志。问题是我每次都构建有签名的(release)apk,但是我在firebase上添加了调试SHA1代码。只是我在模拟器上运行了调试模式。

    EXCEPTION: main
        Process: com.app.surebettips, PID: 3806
        java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { (has extras) }} to activity {com.app.surebettips/com.app.surebettips.Login}: java.lang.IllegalArgumentException: Must specify an idToken or an accessToken.
            at android.app.ActivityThread.deliverResults(ActivityThread.java:3574)
            at android.app.ActivityThread.handleSendResult(ActivityThread.java:3617)
            at android.app.ActivityThread.access$1300(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1352)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
         Caused by: java.lang.IllegalArgumentException: Must specify an idToken or an accessToken.
            at com.google.firebase.auth.GoogleAuthCredential.<init>(Unknown Source)
            at com.google.firebase.auth.GoogleAuthProvider.getCredential(Unknown Source)
            at 

/****HERE***/
com.app.surebettips.Login.firebaseAuthWithGoogle(Login.java:467)
            at com.app.surebettips.Login.onActivityResult(Login.java:376)

/****HERE***/
            at android.app.Activity.dispatchActivityResult(Activity.java:6192)
            at android.app.ActivityThread.deliverResults(ActivityThread.java:3570)
            at android.app.ActivityThread.handleSendResult(ActivityThread.java:3617) 
            at android.app.ActivityThread.access$1300(ActivityThread.java:151) 
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1352) 
            at android.os.Handler.dispatchMessage(Handler.java:102) 
            at android.os.Looper.loop(Looper.java:135) 
            at android.app.ActivityThread.main(ActivityThread.java:5254) 
            at java.lang.reflect.Method.invoke(Native Method) 
            at java.lang.reflect.Method.invoke(Method.java:372) 
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
    09-06 09:49:09.566 3806-3806/com.app.surebettips I/Process: Sending signal. PID: 3806 SIG: 9

线:467

AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);

行:376

firebaseAuthWithGoogle(account);

2 个答案:

答案 0 :(得分:0)

来自Google登录的空响应通常是由于SHA指纹不正确,或者根本没有在Google API控制台中定义。在视频中,作者使用了一个旧教程。 这是当前版本:https://firebase.google.com/docs/auth/android/google-signin 并且包含指向集成教程中标准Google Sing的链接: https://developers.google.com/identity/sign-in/android/sign-in

这是必需的,因为在本教程中还有另一个链接来配置Google API控制台: https://developers.google.com/identity/sign-in/android/start-integrating 您需要在其中配置当前API项目的位置,如果您更改了它或在API控制台中创建了其他项目,则通常将其命名为Google Play Android Developer或其他名称。

您需要在此处设置SHA-1指纹和软件包名称。如果您将其设置为正确的项目(如果您有多个项目),则Google登录将正常运行。

您还使用GoogleSignIn Client,因此在创建Sing In Intent时也必须使用它。

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

因此,请从Google查看本教程,并按照文档所述实施本教程,一切正常。 https://developers.google.com/identity/sign-in/android/start-integrating

答案 1 :(得分:0)

在onActivityResult回调内部执行以下操作:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_SIGN_IN) {
        try {
            Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
            GoogleSignInAccount account = task.getResult(ApiException.class);
            // User is logged in on google platform
            Log.v(TAG, "Account token:" + account.getIdToken()); //NON-NLS
            // Signed in successfully, show authenticated UI.
        } catch (ApiException e) {
            // The ApiException status code indicates the detailed failure reason.
            // Please refer to the GoogleSignInStatusCodes class reference for more information.
            Log.w(TAG, "Google sign in failed", e); //NON-NLS

            String messageToDisplay = "Authentication failed.";
            switch (e.getStatusCode()) {
                case CommonStatusCodes.API_NOT_CONNECTED: //17
                    messageToDisplay += "The client attempted to clearPreferences a method from an API that failed to connect.";
                    break;

                case CommonStatusCodes.DEVELOPER_ERROR: //10
                    messageToDisplay += "The application is misconfigured.";
                    break;

                case CommonStatusCodes.ERROR: //13
                    messageToDisplay += "The operation failed with no more detailed information.";
                    break;

                case CommonStatusCodes.INTERNAL_ERROR: //8
                    messageToDisplay += "An internal error occurred.";
                    break;

                case CommonStatusCodes.INVALID_ACCOUNT: //8
                    messageToDisplay += "Invalid account name specified.";
                    break;

                case CommonStatusCodes.SIGN_IN_REQUIRED: //8
                    messageToDisplay += "Please Sign In to continue.";
                    break;
            }
        }
    }
}

通过这种方式,您将能够了解登录为什么不起作用