0

Calling AccountManager.getAuthToken() with authTokenType = "lh2" for Picasa Web Service now does not return on Android 5.x; getAuthToken with "lh2" still works fine with Android 4.4.x and 6.x, just not 5.x. This was all working fine for Lollipop up until sometime August-September 2016 and nothing changed in the code or app in that time.

Anyone else experiencing this problem with getAuthToken for "lh2" on Lollipop devices? Is there another way to get the account auth token to pass to PicasaWebService?

Here is the relevant code to getAuthToken:

//...

String accountName = "someone@somedamain.com"
Account selectedAccount = null;
AccountManager accountManager = (AccountManager)activity.getSystemService(Context.ACCOUNT_SERVICE);
Account[] list = accountManager.getAccounts();
for (android.accounts.Account a:list) {
    if (a.name.equals(accountName)) {
        selectedAccount = a;
        break;
    }
}

accountManager.invalidateAuthToken("com.google", null);

AccountManagerFuture<Bundle> tokenFuture = getAccountManager().getAuthToken(
    selectedAccount,
    "lh2",
    null,
    activity,
    new OnTokenAcquired(),
    new Handler(new OnTokenError()));   

//...

private class OnTokenAcquired implements AccountManagerCallback<Bundle> {
    @Override
    public void run(AccountManagerFuture<Bundle> result) {
        try {
            Bundle b = result.getResult();
            if (b.containsKey(AccountManager.KEY_INTENT)) {
                Intent intent = b.getParcelable(AccountManager.KEY_INTENT);
                int flags = intent.getFlags();
                flags &= ~Intent.FLAG_ACTIVITY_NEW_TASK;
                intent.setFlags(flags);
                activity.startActivityForResult(intent, REQUEST_AUTHENTICATE);
                return;
            }
            if (b.containsKey(AccountManager.KEY_AUTHTOKEN)) {
                String authToken = b.getString(AccountManager.KEY_AUTHTOKEN);

                // set authtoken to Picasa Web Service
                _picasaService = new PicasawebService("myApp");
                _picasaService.setUserToken(authToken);

                return;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

private class OnTokenError implements Handler.Callback {
    @Override
    public boolean handleMessage(Message msg) {
        Log.e("onError","ERROR");

        return false;
    }
}

//...

Thanks!

Wyatt Wong
  • 19
  • 5

1 Answers1

0

It seems like the authTokenType should be the "OAuth scopes" as found on https://developers.google.com/oauthplayground/ prefixed with "oauth2:".

For Picasa Web, this is https://picasaweb.google.com/data/


accountManager.getAuthToken(account, "oauth2:https://picasaweb.google.com/data/",
               options, false, new GetAuthTokenCallback(), null);
Erik Arvidsson
  • 915
  • 9
  • 10