首页 > 解决方案 > 无法登录 Google 帐户 登录失败

问题描述

我已经在我的应用程序中创建了 Google 和 Facebook 登录但我无法通过它显示的 Google 帐户登录SignIn failed

我已经看到它没有显示错误的代码,应用程序也没有崩溃,但我无法通过谷歌登录。我尝试了许多不同的谷歌账户,但每次它显示“登录失败”。

    private void signIn() {
    if (checkPermission()) {
        if (UtilityMethods.isInternetAvailable(mContext)) {
            new GetQuestionOfTheDay(mContext).execute();
            new GetQuickTen(mContext).execute();
            loginType = "Google";
            Intent signInIntent = mGoogleSignInClient.getSignInIntent();
            startActivityForResult(signInIntent, RC_SIGN_IN);
        } else {
            UtilityMethods
                    .showAlert(mContext, "No Internet Connection", 
   "Please enable internet connection to login.",
                               "Ok");
        }
    } else {
        requestPermission(ChoiceActivity.this);
    }
 }

 private void fbSignIn() {
    if (checkPermission()) {
        if (UtilityMethods.isInternetAvailable(mContext)) {
            new GetQuestionOfTheDay(mContext).execute();
            new GetQuickTen(mContext).execute();
            loginType = "Facebook";
            loginButton.performClick();
        } else {
            UtilityMethods
                    .showAlert(mContext, "No Internet Connection", 
 "Please enable internet connection to login.",
                               "Ok");
        }
    } else {
        requestPermission(ChoiceActivity.this);
    }
}

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

    // Result returned from launching the Intent from 
 GoogleSignInClient.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        // The Task returned from this call is always completed, no need 
to attach a listener.
        Task<GoogleSignInAccount> task = 
   GoogleSignIn.getSignedInAccountFromIntent(data);
        handleSignInResult(task);
    }
 }

  private void handleSignInResult(Task<GoogleSignInAccount> 
   completedTask) {
    try {
        GoogleSignInAccount account = 
     completedTask.getResult(ApiException.class);
        displayName = account.getDisplayName();
        socialMailId = account.getEmail();
        new Registration().execute();
    } catch (ApiException e) {
        // The ApiException status code indicates the detailed failure 
    reason.
        // Please refer to the GoogleSignInStatusCodes class reference 
   for more information.
        AppUtil.log(TAG, "signInResult:failed code=" + e.getStatusCode(), 
   e);
        Toast.makeText(mContext, "SignIn Failed ...", 
     Toast.LENGTH_SHORT).show();
        databaseHandler.flushQuickTenData();
        // updateUI(null);
    }
 }

 @Override
 public void onRequestPermissionsResult(int requestCode, @NonNull 
 String[] permissions,
                                       @NonNull int[] grantResults) {
    switch (requestCode) {
        case MY_REQUEST: {
            if (grantResults.length > 0) {
                boolean isReadExternalStoragePermission = grantResults[0] 
  == PackageManager.PERMISSION_GRANTED;
                boolean isWriteExternalStoragePermission = 
  grantResults[1] == PackageManager.PERMISSION_GRANTED;
                if (isReadExternalStoragePermission && 
 isWriteExternalStoragePermission) {
                    Toast.makeText(ChoiceActivity.this, "All Permission 
    Granted", Toast.LENGTH_SHORT).show();
                    isAccess = true;
                } else {
                    isAccess = false;
                    int i = 0;
                    StringBuilder stringBuilder = new StringBuilder();
                    if (isReadExternalStoragePermission && 
    isWriteExternalStoragePermission) {
                        if (i == 1) {
                            stringBuilder.append(", Storage");
                        } else {
                            stringBuilder.append("Storage");
                        }
                    }
                    Toast.makeText(ChoiceActivity.this, 
    stringBuilder.toString() + " Permission Denied",
                                   Toast.LENGTH_SHORT).show();
                }
            }
            break;
        }
     }
 }

我尝试调试应用程序,所以当我按下谷歌中的帐户按钮时,它会在我的调试器中显示此错误。

 E/ChoiceActivity: signInResult:failed code=10
 com.google.android.gms.common.api.ApiException: 10:       at 
 com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus
 (UnknownSource) at 
 com.google.android.gms.auth.api.signin.GoogleSignIn.
 getSignedInAccountFromIntent(Unknown Source)
    at com.taxsmart.activity.ChoiceActivity.onActivityResult
    (ChoiceActivity.java:284)
    at android.app.Activity.dispatchActivityResult(Activity.java:6461)
    at android.app.ActivityThread.deliverResults
    (ActivityThread.java:3960)
    at android.app.ActivityThread.handleSendResult
    (ActivityThread.java:4007)
    at android.app.ActivityThread.-wrap16(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage
   (ActivityThread.java:1551)
    at android.os.Handler.dispatchMessage(Handler.java:111)
    at android.os.Looper.loop(Looper.java:207)
    at android.app.ActivityThread.main(ActivityThread.java:5763)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
    (ZygoteInit.java:789)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)"

标签: javaapiandroid-studiogoogle-signin

解决方案


推荐阅读