How to sign out of a Google Drive account?

孤街醉人 提交于 2019-12-12 19:26:34

问题


How do I log out of the Google Drive service? I do not want to switch accounts but to log out definitively.

I am working on an app that will use the user's Google Drive storage among other storage services. Therefore I need to allow the user to sign out of Google Drive.


回答1:


Leaving aside I think this is a poor API implementation, this is how you log out.

mGoogleApiClient.unregisterConnectionCallbacks(mConnectionCallbacksListener);
mGoogleApiClient.unregisterConnectionFailedListener(mOnConnectionFailedListener);
mGoogleApiClient.clearDefaultAccountAndReconnect();

The unregistration of the callbacks is to avoid the API showing the Google Account picker, in other words, to avoid reconnecting. Remember to set the callbacks again if you are going to sign in to any Google service later!

Optionally, you can get the operation's result:

mGoogleApiClient.clearDefaultAccountAndReconnect().setResultCallback(new ResultCallback<Status>() {
        @Override
        public void onResult(Status status) {
            // Optional
        }
    });



回答2:


I found that this works. These are the same sign in options I use. Replace with your own.

I put this right before my sign in code so the user chooses an account each time.

    val signInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestScopes(Drive.SCOPE_FILE).requestScopes(Drive.SCOPE_APPFOLDER).build()
    val googleSignInClient = GoogleSignIn.getClient(this, signInOptions)
    googleSignInClient.signOut()


来源:https://stackoverflow.com/questions/30776838/how-to-sign-out-of-a-google-drive-account

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!