如何清除GoogleApiClient默认帐户和凭证 [英] How to Clear GoogleApiClient Default Account and Credentials

查看:274
本文介绍了如何清除GoogleApiClient默认帐户和凭证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将GoogleApiClient连接到Google云端硬盘。我构建这样的客户端:

I connect a GoogleApiClient for use with Google Drive. I build the client like this:

        GoogleApiClient.Builder(this)
                .addApi(Drive.API)
                .addScope(Drive.SCOPE_FILE)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();

我的经验是,连接请求的第一次此客户端会显示 AccountPicker 对话框, Google云端硬盘的同意画面。如果用户选择一个帐户并同意,并且连接成功完成,则AccountManager或某些相关功能会将所选帐户保存为默认帐户,并将Drive范围的凭证(OAuth令牌?)保存为默认帐户。在后续的连接请求中,为了方便用户,使用了保存的值,并且用户没有看到用户帐户选择或同意的用户界面。

My experience has been that the first time a connection request is made for this client, the AccountPicker dialog is presented and the consent screen for Google Drive. If the user selects an account, consents, and the connection completes successfully, the AccountManager or some related function saves the selected account as the default account, and the credentials (OAuth tokens?) for the Drive scope. On subsequent connection requests, as a convenience to the user, the saved values are used and the user does not see the UI for account selection or consent.

对于开发测试,我希望能够清除默认帐户并保存凭据,以便我可以执行连接失败解决处理。我还没有找到办法做到这一点。我尝试过这样没有成功:

For development testing, I would like to be able to clear the default account and saved credentials so that I can exercise my connection failure resolution processing. I have not found a way to do this. I tried this without success:

String driveScope = "https://www.googleapis.com/auth/drive.file";
String tokenType = "oauth2:" + driveScope;

AccountManager.get(this).invalidateAuthToken(
    GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE, tokenType);


推荐答案

听起来你应该调用 clearDefaultAccountAndReconnect() GoogleApiClient 清除选中的帐户信息。

It sounds like you should call clearDefaultAccountAndReconnect() on your GoogleApiClient to clear the selected account information.

这篇关于如何清除GoogleApiClient默认帐户和凭证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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