我正在使用谷歌播放服务静默登录,但它始终是CompleteListener show com.google.android.gms.common.api.ApiException:4:' SIGN_IN_REQUIRED'但我是我的应用程序中的测试用户。我的代码如下,
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGoogleSignInClient = GoogleSignIn.getClient(this, new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN).build());
}
@Override
protected void onResume() {
super.onResume();
signInSilently();
}
private void signInSilently() {
mGoogleSignInClient.silentSignIn().addOnCompleteListener(this, new OnCompleteListener<GoogleSignInAccount>() {
@Override
public void onComplete(@NonNull Task<GoogleSignInAccount> task) {
if (task.isSuccessful()) {
try {
GoogleSignInAccount signInAccount = task.getResult(ApiException.class);
} catch (ApiException apiException) {
System.out.println("CATE_RESULT_CODE " + apiException.getLocalizedMessage()+" " +apiException.getStatusMessage()+ " " +apiException.getMessage()+ " "+apiException.getCause() );
}
} else {
try {
GoogleSignInAccount signInAccount = task.getResult(ApiException.class);
} catch (ApiException apiException) {
System.out.println("CATE_RESULT_CODE " + apiException.getLocalizedMessage()+" " +apiException.getStatusMessage()+ " " +apiException.getMessage()+ " "+apiException.getCause() );
}
}
}
});
}
我的gradle文件依赖项:
dependencies {
ext {
support_library_version = '27.0.2'
google_play_services_version = '15.0.2'
}
implementation "com.android.support:appcompat-v7:${support_library_version}"
implementation "com.android.support:design:${support_library_version}"
implementation "com.android.support:recyclerview-v7:${support_library_version}"
implementation "com.android.support:cardview-v7:${support_library_version}"
implementation 'com.google.android.gms:play-services-auth:15.0.1'
implementation 'com.google.android.gms:play-services-games:15.0.1'
}
erorr :
com.google.android.gms.common.api.ApiException: 4:
at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(Unknown Source)
at com.google.android.gms.common.internal.zzk.convert(Unknown Source)
at com.google.android.gms.common.internal.zzl.onComplete(Unknown Source)
at com.google.android.gms.common.api.internal.BasePendingResult.zza(Unknown Source)
at com.google.android.gms.common.api.internal.BasePendingResult.setResult(Unknown Source)
at com.google.android.gms.auth.api.signin.internal.zzk.zzd(Unknown Source)
at com.google.android.gms.auth.api.signin.internal.zzu.dispatchTransaction(Unknown Source)
at com.google.android.gms.internal.auth.zze.onTransact(Unknown Source)
at android.os.Binder.execTransact(Binder.java:404)
at dalvik.system.NativeStart.run(Native Method)
还在Manifest文件中添加app id。
请给我一个解决这个问题的方法。提前谢谢
答案 0 :(得分:0)
错误将被解决......
任何遇到此类问题的人请首先检查Firebase项目设置中的SHA 1密钥。
我的SHA 1密钥与Firebase项目设置不匹配。
现在我改变了并完美地工作..
谢谢..
答案 1 :(得分:0)
事实证明,每当您添加/编辑 Firebase 应用程序设置(SHA证书指纹)时,它都会在应用程序 Google Api 控制台中生成相关凭据。尽管指纹是相同的,但直到我从Google Api删除了该笔迹并让Firebase为我生成它后,它才起作用-我猜它的ID有关。
答案 2 :(得分:0)
执行以下步骤,直到在Android Studio中获得SHA-1
然后转到此链接
中提琴。