Google Account Receive Token

I have a problem with kitkat api, while tringy to get google google services access token, google music in my case. So, if the user tries to get the token first, using the following method:

public String getAuthToken(Account account) throws AuthenticatorException, IOException { String s1; if (account == null) { Log.e("MusicAuthInfo", "Given null account to MusicAuthInfo.getAuthToken()", new Throwable()); throw new AuthenticatorException("Given null account to MusicAuthInfo.getAuthToken()"); } String s = getAuthTokenType(mContext); try { s1 = AccountManager.get(mContext).blockingGetAuthToken(account, s, true); } catch (OperationCanceledException operationcanceledexception) { throw new AuthenticatorException(operationcanceledexception); } if (s1 == null) { throw new AuthenticatorException("Received null auth token."); } return s1; } 

here I get s1 == null and a system startup notification:

notification

When the user clicks on the notification, the following dialog box appears:

dialog

When the user clicks “ok”, all subsequent iterations receiving the token will succeed.

Question: How to bypass this confirmation or show only a dialog without clicking on the notification?

+6
source share
2 answers

This is not a direct answer to your question, but you can use Google Play Services.

 String token = GoogleAuthUtil.getToken(context, userEmail, "oauth2:https://mail.google.com/"); 

You just need to specify the oauth2 area that you need. For example, for Google+, you’ll need " https://www.googleapis.com/auth/plus.login instead of what I post in the Gmail snippet. You can also specify multiple areas in a single token request. A permission request appears immediately.

You can read all about it here: Authorization using the API for the REST API , Application Areas

+2
source

solved. You need to use this method:

 Bundle result = AccountManager.get(activity).getAuthToken(account, s, new Bundle(), activity, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> future) { try { Log.e("xxx", future.getResult().toString()); } catch (OperationCanceledException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (AuthenticatorException e) { e.printStackTrace(); } } }, null).getResult(); 
-1
source

Source: https://habr.com/ru/post/977875/


All Articles