android - 在 Android 上使用 GoogleSignInClient 静默签名时出现 ApiException

标签 android google-api google-signin

当我尝试在 Android 上静默登录时,我经常遇到以下错误。我该如何调试。这是什么原因。 (我的 Android 手机上有一个有效的 Google 帐户。)

signInSilently(): failure
com.google.android.gms.common.api.ApiException: 4: 
at com.google.android.gms.common.internal.zzb.zzz(Unknown Source)
at com.google.android.gms.common.internal.zzbk.zzaa(Unknown Source)
at com.google.android.gms.common.internal.zzbl.zzs(Unknown Source)
at com.google.android.gms.common.api.internal.zzs.zzc(Unknown Source)
at com.google.android.gms.common.api.internal.zzs.setResult(Unknown Source)
at com.google.android.gms.auth.api.signin.internal.zzg.zza(Unknown Source)
at com.google.android.gms.auth.api.signin.internal.zzt.onTransact(Unknown Source)
at android.os.Binder.execTransact(Binder.java:446)

代码如下

 mGoogleSignInClient.silentSignIn().addOnCompleteListener(activity,
     new OnCompleteListener<GoogleSignInAccount>() {
        @Override
        public void onComplete(@NonNull Task<GoogleSignInAccount> task) {
             if (task.isSuccessful()) {
                   Log.d(TAG, "signInSilently(): success");
                   onConnected(task.getResult());
             } else {
               Log.d(TAG, "signInSilently(): failure", task.getException());
                        Toast.makeText(activity, "A sign-in problem encountered.",
                                Toast.LENGTH_SHORT).show();
                        onDisconnected();
             }
          }
       });

最佳答案

a list of error codes

据此,您的错误代码表示如下:

public static final int SIGN_IN_REQUIRED
The client attempted to connect to the service but the user is not signed in. The client may choose to continue without using the API. Alternately, if hasResolution() returns true the client may call startResolutionForResult(Activity, int) to prompt the user to sign in. After the sign in activity returns with RESULT_OK further attempts should succeed.

Constant Value: 4

这意味着,用户需要手动登录才能使用silentSignIn。你可以找到一个例子 on Google github

关于android - 在 Android 上使用 GoogleSignInClient 静默签名时出现 ApiException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48923966/

相关文章:

c# - 如何使用 Google.Apis.Drive.V3 断开(删除访问)谷歌驱动器?

google-api - 在给定用户 ID 和访问 token 的情况下获取谷歌用户配置文件

ios - 使用 Firebase 应用程序打开 url 选项的 GoogleSignIn 未调用

android - Google 登录但结果代码为 0

javascript - google+ api 登录不返回电子邮件

Android 布局高度最小值为 match_parent,但如果 content 大于 parent,则为 wrap_content

Android Webview 不显示弹出窗口

java - 防止 SearchView 折叠

java - 当使用相应的值代替时如何获取 key ?

javascript - 使用 google drive api 上传 excel 文件