简体   繁体   English

Android上的Google登录-由于未登录而无法登录

[英]Google SignIn on Android - Log out does not work since not logged in

I have integrated Google SignIn via this guide ( https://developers.google.com/identity/sign-in/android/start-integrating ). 我已通过本指南( https://developers.google.com/identity/sign-in/android/start-integrating )集成了Google SignIn。

I've done setup like this: 我已经完成了这样的设置:

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .requestIdToken(AppActivity.this.getResources().getString(R.string.server_client_id))
            .build();

GoogleSignIn.googleApiClient = new GoogleApiClient.Builder(this)
            .addOnConnectionFailedListener(this)
            .addConnectionCallbacks(this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

Sign in works with the following code and works perfectly fine: 使用以下代码登录即可正常运行:

public static void loginGoogleSDK()
{
    Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient);
    GameApplication.getActivity().startActivityForResult(signInIntent, RC_SIGN_IN);
}

The SignIn-Overlay appears, I choose an account and log in. Everything works fine. 出现登录覆盖,我选择一个帐户并登录。一切正常。

Then I try to call logout with the following code after this guide ( https://developers.google.com/identity/sign-in/android/disconnect ), but I always the the error message: Cannot log out, since not logged in . 然后,在本指南( https://developers.google.com/identity/sign-in/android/disconnect )之后,我尝试使用以下代码调用注销,但是我始终收到错误消息: 无法注销,因为未记录在

Auth.GoogleSignInApi.signOut(googleApiClient).setResultCallback(
        new ResultCallback<Status>() {
            @Override
            public void onResult(Status status) {
                System.out.println("Google SDK Sign Out Access Status:" + status);
            }
        });

The weird part is, that if I call login again, it is automatically successful and I can not choose an account again. 奇怪的是,如果我再次调用登录名,它将自动成功,并且我无法再次选择帐户。 Hence, the login is still active and I can not log out. 因此,登录仍处于活动状态,我无法注销。

Per the enableAutoManage documentation , including it: 根据enableAutoManage文档 ,包括:

Enables automatic lifecycle management in a support library FragmentActivity that connects the client in onStart() and disconnects it in onStop() . 在支持库FragmentActivity中启用自动生命周期管理,该库在onStart()中连接客户端,并在onStop()断开客户端连接。

It handles user recoverable errors appropriately and calls onConnectionFailed(ConnectionResult) on the unresolvedConnectionFailedListener if the ConnectionResult has no resolution. 如果ConnectionResult没有解决方案,它将适当地处理用户可恢复的错误,并在unresolvedConnectionFailedListener上调用onConnectionFailed(ConnectionResult) This eliminates most of the boiler plate associated with using GoogleApiClient . 这消除了与使用GoogleApiClient相关的大多数GoogleApiClient

By not including enableAutoManage() like the Add Sign In guide does, your GoogleApiClient never actually connects, causing the error you are experiencing. 通过不像“ 添加登录”指南那样包含enableAutoManage() ,您的GoogleApiClient永远不会真正连接,从而导致您遇到的错误。

If you don't want to use enableAutoManage() , you can follow the instructions to manually manage connections including providing an implementation for ConnectionCallbacks and OnConnectionFailedListener . 如果不想使用enableAutoManage() ,则可以按照说明手动管理连接,包括提供ConnectionCallbacksOnConnectionFailedListener的实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM