The below code snippet produces an invalid auth_token (verified through https://accounts.google.com/o/oauth2/tokeninfo?access_token=) when run on android 2.3.
The only way to get AccountManager return the valid one is to manually go through account settings and remove than add an existing google account. When rerun the token will be valid until not expired, than the same issue reappears. Note that the problem is not occurring on devices with android 4.0 and higher.
Can you please assist in sorting this out?
private static final String SCOPE = "oauth2:https://www.googleapis.com/auth/userinfo.email";
accountManager.getAuthToken(googleAccountsMap.get(accountName), SCOPE, null, getActivity(),
new OnAuthTokenAcquired(), null);
private class OnAuthTokenAcquired implements AccountManagerCallback<Bundle> {
@Override
public void run(AccountManagerFuture<Bundle> result) {
try {
Bundle bundle = result.getResult();
String accountName = bundle.getString(AccountManager.KEY_ACCOUNT_NAME);
String authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN);