频繁登录和注销后,Google登录失败 [英] Google sign in failed after frequent signing in and out

查看:349
本文介绍了频繁登录和注销后,Google登录失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以多次使用Google帐户登录我的应用。
一切都很好。



但是如果我在一到两分钟内登出约20次,
Google登录失败,并在 onActivityResult 函数中返回错误代码12501,resultCode = 0;

我正在使用手机:Nexus 6,Android 5.1.1

以下是我的代码:

  private GoogleSignInOptions mGso; 
私有GoogleApiClient mGac;

public void init(@NonNull final BaseActivity activity){
mGso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(activity.getString(R.string.default_web_client_id ))
.requestEmail()
.build();

mGac = new GoogleApiClient.Builder(activity)
.enableAutoManage(activity / * FragmentActivity * /,new GoogleApiClient.OnConnectionFailedListener(){
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult){
ToastUtils.show(activity,R.string.login_failed);
}
})
.addApi(Auth.GOOGLE_SIGN_IN_API,mGso)
.build();

$ b $ public void signIn(@NonNull final BaseActivity activity,
@NonNull GoogleSignInCallback callback,
@NonNull final OnLoadingListener< PlatformUserEntity>侦听器){

callback.registerCallback(listener);
意图signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGac);
activity.startActivityForResult(signInIntent,REQUEST_GOOGLE_SIGNIN);

//断开客户端
mGac.stopAutoManage(activity);
mGac.disconnect();


$ / code $ / pre
$ b $ p

这里是gradle:

  compile'c​​om.google.android.gms:play-services-base:9.6.1'
compile'c​​om.google.android.gms: play-services-gcm:9.6.1'
compile'c​​om.google.android.gms:play-services-auth:9.6.1'

Fisrt,我用FragmentActivity初始化GoogleApiClient,然后signIn函数启动Acitvity。 GoogleSignInCallback已在onActivityResult函数中注册。然后断开客户端,因为每次单击登录按钮时,都会调用init函数。



我怀疑我是否使用 stopAutoManage() 太早,但似乎并非如此。
所以我很困惑,哪一部分可能是错误的?



我注意到了日志:

 无法设置套接字写入超时:null 
12-03 17:21:43.859 264-264 /? W / SurfaceFlinger:无法登录到二进制事件日志:溢出。
12-03 17:21:43.902 1946-12870 /? W / Conscrypt:无法设置套接字写入超时:空
12-03 17:21:44.327 21168-21168 /? W / AccountChipsFragment:录制同意失败。
12-03 17:21:44.657 29359-29782 /? E / TokenRequestor:您有错误的OAuth2相关配置,请检查。详细错误:UNREGISTERED_ON_API_CONSOLE
12-03 17:21:44.664 812-1072 /? W / ActivityManager:getRunningAppProcesses:调用者10145不保存REAL_GET_TASKS;限制输出
12-03 17:21:44.697 21168-21168 /? W / AutoManageHelper:连接客户端时发生未解决的错误。停止自动管理。

它表示您有错误的OAuth2相关配置,但我可以使用Web客户端ID来请求在第一次IdToken。



这只是让我更困惑。



我也发现了一个奇怪的事情。如果我安装了本地构建的apk,则此错误从未发生过。如果我从谷歌播放商店下载,此错误发生。但这两个apks之间没有区别,因为我提供的是本地的google商店。

解决方案

最后我找到了原因。
我的公司的发布程序再次签署了我的apk。
该过程使用另一个密钥库,以便更改我的sha1密钥。
我在google开发控制台中配置了新的sha1键,这个bug已经解决了。

但是我仍然感到困惑,如果我使用debug keystore apk ,成功登录并卸载它,然后我安装谷歌播放apk中有不同的sha1键,谷歌登录可以工作一些times.It不会立即告诉我错。


I can sign in my app with Google account at first several times. Everything is fine.

But if I sign in and out about 20 times in a one or two minutes. Google sign in failed and in onActivityResult function, it returns error code 12501, resultCode = 0;

I'm using the phone: Nexus 6, Android 5.1.1

Here is my code:

private GoogleSignInOptions mGso;
private GoogleApiClient mGac;

public void init(@NonNull final BaseActivity activity) {
    mGso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(activity.getString(R.string.default_web_client_id))
            .requestEmail()
            .build();

    mGac = new GoogleApiClient.Builder(activity)
            .enableAutoManage(activity /* FragmentActivity */, new GoogleApiClient.OnConnectionFailedListener() {
                @Override
                public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
                    ToastUtils.show(activity, R.string.login_failed);
                }
            })
            .addApi(Auth.GOOGLE_SIGN_IN_API, mGso)
            .build();
}

public void signIn(@NonNull final BaseActivity activity,
                   @NonNull GoogleSignInCallback callback,
                   @NonNull final OnLoadingListener<PlatformUserEntity> listener) {

    callback.registerCallback(listener);
    Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGac);
    activity.startActivityForResult(signInIntent, REQUEST_GOOGLE_SIGNIN);

    // disconnect the client
    mGac.stopAutoManage(activity);
    mGac.disconnect();

}

Here is gradle:

compile 'com.google.android.gms:play-services-base:9.6.1'
compile 'com.google.android.gms:play-services-gcm:9.6.1'
compile 'com.google.android.gms:play-services-auth:9.6.1'

Fisrt, I init the GoogleApiClient with a FragmentActivity, then signIn function starts the Acitvity. GoogleSignInCallback is registered in the onActivityResult function. Then disconnect the Client because every time the sign in button is clicked, the init function will be invoked.

I doubt that I use stopAutoManage() too early but it seems like not true. So I'm confused, which part might be wrong?

I noticed the log:

Could not set socket write timeout: null
12-03 17:21:43.859 264-264/? W/SurfaceFlinger: couldn't log to binary event log: overflow.
12-03 17:21:43.902 1946-12870/? W/Conscrypt: Could not set socket write timeout: null
12-03 17:21:44.327 21168-21168/? W/AccountChipsFragment: Recording consent failed.
12-03 17:21:44.657 29359-29782/? E/TokenRequestor: You have wrong OAuth2 related configurations, please check. Detailed error: UNREGISTERED_ON_API_CONSOLE
12-03 17:21:44.664 812-1072/? W/ActivityManager: getRunningAppProcesses: caller 10145 does not hold REAL_GET_TASKS; limiting output
12-03 17:21:44.697 21168-21168/? W/AutoManageHelper: Unresolved error while connecting client. Stopping auto-manage.

It said "You have wrong OAuth2 related configuration", but I could use the web client id to request the IdToken at the first time.

It just makes me more confused.

I also found a strange thing. If I install the apk which is built locally, this error never happened. If I download from google play store, this error ocurred. But there is no difference between these two apks because I deliver google store with the local one.

解决方案

Finally I found the reason. My apk was signed again by our company's release procedure. The procedure used another keystore so my sha1 key was changed. I configure the new sha1 key in google develop console, this bug is solved.

But I'm still confused that, if I use the debug keystore apk, got sign in successfully and uninstall it, then I install the google play apk which has different sha1 key, google sign in can work some times.It won't tell me wrong immediately.

这篇关于频繁登录和注销后,Google登录失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆