我正在尝试对帐户进行身份验证,但仅在响应中获取帐户名,帐户类型。我如何获取所有帐户详细信息,例如访问令牌,刷新令牌,令牌到期时间,帐户名,帐户类型。这样我就可以检查令牌是否已过期/有效。我的代码如下:
if(accountsFromFirstApp.length >= 1) {
System.out.println("Account found.");
for(Account acct: accountsFromFirstApp){
System.out.println("am.getAccounts()"+ am.getAccounts());
// String authToken = am.peekAuthToken(accountsFromFirstApp[0], getString(R.string.auth_type));
System.out.println("acct.name "+ acct.name);
AccountManagerFuture<Bundle> ah = am.getAuthToken(accountsFromFirstApp[0], "ah", false, null, null);
System.out.println("userdata "+ am.getAuthToken(accountsFromFirstApp[0], "ah", false, null, null)); // Get the auth token
//Bundle options = null;
Activity activity = null;
AccountManagerCallback<Bundle> callback = null;
Handler handler = null;
AccountManagerFuture<Bundle> future = am.getAuthToken(
acct, AUTH_TYPE, options, activity, callback, handler);
try {
String token = future.getResult().getString(AccountManager.KEY_AUTHTOKEN);
System.out.println("token:"+ token);
} catch(Exception e) {
e.printStackTrace();
}
// System.out.println("acct.user.data "+ am.getUserData(acct, "key.for.secure.user.data"));
}
}else{
System.out.println("No account found!");
}