Currently, I am working on the application where user able to login with Google. As part of the login process, we need to send Google ACCESS TOKEN and REFRESH TOKEN to serve
I think you need to try this code in AsyncTask like below.
private class RetrieveTokenTask extends AsyncTask {
@Override
protected String doInBackground(String... params) {
String accountName = params[0];
String scopes = "oauth2:profile email";
String token = null;
try {
token = GoogleAuthUtil.getToken(getApplicationContext(), accountName, scopes);
} catch (IOException e) {
Log.e(TAG, e.getMessage());
} catch (UserRecoverableAuthException e) {
startActivityForResult(e.getIntent(), REQ_SIGN_IN_REQUIRED);
//REQ_SIGN_IN_REQUIRED = 55664;
} catch (GoogleAuthException e) {
Log.e(TAG, e.getMessage());
}
return token;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
Log.i("AccessToken",s);
}
}
Then call AsyncTask like below to get Access Token:
...
new RetrieveTokenTask().execute(mAccountName);
Check here. I hope it's help you.