Reputation: 2576
I'm trying to access User in one of my endpoints but can't get the magic to happen from Android. The documentation seems to be in a somewhat broken state, seeing how it is just transitioning from the trusted-tester program, and I'm seeing conflicting information, so I'm hoping someone here can help me out.
I've created my client id for Android in the API console. I'm specifying it as a client id and audience in my endpoint like so:
@Api(
name = "tictactoe",
clientIds = {"myAndroidClientId.apps.googleusercontent.com"},
audiences = {"myAndroidClientId.apps.googleusercontent.com"}
)
In my Android activity, I'm creating my credential:
credential = GoogleAccountCredential.usingAudience(this, "server:client_id:myAndroidClientId.apps.googleusercontent.com");
credential.setSelectedAccountName(myAccountName);
and am using that to build my service before making a network call in an AsyncTask:
Builder builder = new MyService.Builder(transport, jsonFactory, credential);
MyService service = builder.build();
thing = service.things().get().execute();
which then throws this exception:
com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAuthIOException
Caused by:
com.google.android.gms.auth.GoogleAuthException: Unknown
com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:192)
com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:217)
Thanks in advance for your help!
Upvotes: 3
Views: 2085
Reputation: 2576
Figured out where I went wrong:
You have to specify the WEB client id as the audience in @API, and also in Android. The android client id is only used in the @API clientIds.
Upvotes: 4