I am trying to get Auth Token on Android which can be exchanged for accessToken and RefreshToken on my webserver.
I am following this documentation.
Specifically the section - Android app obtains offline access for web back-end
My code:
String WEB_APP_CLIENT_ID = "***.apps.googleusercontent.com";
String scopes = "oauth2:server:client_id:" + WEB_APP_CLIENT_ID+":api_scope:" + Scopes.PLUS_LOGIN + " https://www.googleapis.com/auth/plus.profile.emails.read";
//String this_scope_works_but_gives_access_token = "oauth2:" + Scopes.PLUS_LOGIN + " https://www.googleapis.com/auth/plus.profile.emails.read";
try {
String authToken = GoogleAuthUtil.getToken(AttachEmailActivity.this, account,scopes);
} catch (GoogleAuthException e) {
e.printStackTrace();
}
But it's always giving me following exception:
com.google.android.gms.auth.GoogleAuthException: Unknown
com.google.android.gms.auth.GoogleAuthUtil.zza(Unknown Source)
com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
app.activities.AttachEmailActivity$1.run(AttachEmailActivity.java:437)
I have read and tried out almost all solutions on similar problems it is still failing. I have tried using all different client IDs - including web client id, server application id, android client id, other client id
In fact, I used rest API outside my JAVA application using the same web client ID and I was able to get the required auth code.
https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=****.apps.googleusercontent.com&redirect_uri=http://localhost&scope=https://www.googleapis.com/auth/plus.login&access_type=offline
But in Java application, I am only getting the "Unknown" exception. Can't google give more information? What's unknown? Is there a way to get the com.google.android.gms.auth package code and see where the exception is being thrown from?