0
我正在使用新的Google登录对我的应用程序中的用户进行身份验证。我正在按照官方文档进行集成。无法处理Google登录中的不同错误场景
https://developers.google.com/identity/sign-in/android/start
我已经产生WEB_CLIENT_ID和我能够成功登录,用户。 但我在处理错误场景时遇到问题。
我的应用程序有2个主要的错误情况,我想为他们显示不同的错误信息。
- 当显示帐户选择器对话框,并且用户按下后退按钮,那么我需要显示“用户已取消操作”。
- 当用户从该帐户对话框选择器选择一个帐户,他失去了在此期间,他的互联网连接,然后我需要表现出“有一些问题,与网络”
我现在面临的问题就是在这两个操作上,google auth api都会返回状态码12501.因此,我无法根据api返回的状态提供不同的错误消息。这是我到目前为止尝试过的代码。
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQ_CODE_GOOGLE) {
/* Google SignIn Callback result*/
if (data == null) {
return;
}
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (result == null) {
return;
}
if (result.isSuccess()) {
// Signed in successfully, get idToken and userID.
} else {
// Login not successful.
Status status = result.getStatus();
if (status == null) {
return;
}
if (status.isCanceled()) {
//User canceled the operation
} else if (status.getStatusCode() == CommonStatusCodes.INVALID_ACCOUNT) {
//Invalid account
} else {
//Generic error
}
}
}
}
但是每次谷歌登录失败时,它总是进入else状态。无法弄清楚如何为不同类型的错误提供不同的错误消息?