如何清除 GoogleApiClient 默认帐户和凭据
How to Clear GoogleApiClient Default Account and Credentials
我连接了一个 GoogleApiClient 用于 Google Drive。我这样构建客户端:
GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
我的经验是 第一次 为该客户端发出连接请求时,会出现 AccountPicker 对话框和 [=21= 的同意屏幕] 驾驶。如果用户选择一个帐户,同意,并且连接成功完成,AccountManager 或一些相关功能会将所选帐户保存为默认帐户,以及 Drive 范围的凭据(OAuth 令牌?)。在后续的连接请求中,为了方便用户,将使用保存的值,并且用户不会看到 UI 用于帐户选择或同意。
对于开发测试,我希望能够清除默认帐户和保存的凭据,以便我可以练习我的连接失败解决处理。我还没有找到一种方法来做到这一点。我尝试了这个但没有成功:
String driveScope = "https://www.googleapis.com/auth/drive.file";
String tokenType = "oauth2:" + driveScope;
AccountManager.get(this).invalidateAuthToken(
GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE, tokenType);
听起来你应该在 GoogleApiClient
上调用 clearDefaultAccountAndReconnect() 来清除所选的帐户信息。
我连接了一个 GoogleApiClient 用于 Google Drive。我这样构建客户端:
GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
我的经验是 第一次 为该客户端发出连接请求时,会出现 AccountPicker 对话框和 [=21= 的同意屏幕] 驾驶。如果用户选择一个帐户,同意,并且连接成功完成,AccountManager 或一些相关功能会将所选帐户保存为默认帐户,以及 Drive 范围的凭据(OAuth 令牌?)。在后续的连接请求中,为了方便用户,将使用保存的值,并且用户不会看到 UI 用于帐户选择或同意。
对于开发测试,我希望能够清除默认帐户和保存的凭据,以便我可以练习我的连接失败解决处理。我还没有找到一种方法来做到这一点。我尝试了这个但没有成功:
String driveScope = "https://www.googleapis.com/auth/drive.file";
String tokenType = "oauth2:" + driveScope;
AccountManager.get(this).invalidateAuthToken(
GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE, tokenType);
听起来你应该在 GoogleApiClient
上调用 clearDefaultAccountAndReconnect() 来清除所选的帐户信息。