We're under Android (Jellybean and higher), and we've got an app which need to use OAuth2 with Google for authentication.
I simplified the login activity, but it's looking like that:
AccountManager mAccountManager;
// [...]
Account account = new Account("myEmail@gmail.com", "com.google");
// same with professional email managed by Google as myEmail@myDomain.com
// real code recovers accounts with mAccountManager.getAccountsByType("com.google")
mAccountManager = AccountManager.get(getBaseContext());
mAccountManager.getAuthToken(account, "oauth2:https://www.googleapis.com/auth/userinfo.email", null, MyActivity.this, new AccountManagerCallback<Bundle>() {
@Override
public void run(AccountManagerFuture<Bundle> accountManagerFuture) {
try {
String token = accountManagerFuture.getResult().getString(AccountManager.KEY_AUTHTOKEN);
// exception occurs here
// [...]
} catch (Exception e) {
Log.e("account", "exception occurs", e);
}
}
}, null);
When we call accountManagerFuture.getResult()
, it fires this exception:
android.accounts.AuthenticatorException: UNREGISTERED_ON_API_CONSOLE
at android.accounts.AccountManager.convertErrorToException(AccountManager.java:2024)
at android.accounts.AccountManager.access$400(AccountManager.java:144)
at android.accounts.AccountManager$AmsTask$Response.onError(AccountManager.java:1867)
at android.accounts.IAccountManagerResponse$Stub.onTransact(IAccountManagerResponse.java:69)
at android.os.Binder.execTransact(Binder.java:446)
I cannot find neither doc about this nor other people with the same exception, and I'm quite confused: the call to AccountManager.getAuthToken
only provides an account (name and type), a scope, and a callback method, there's no parameter to specify an app or something I could customize in the dev API console.
I'm sure I'm missing something, but what?