How exactly to set clientIds and audiences to authenticate Google Cloud Endpoints for an Android App

android, google-cloud-endpoints

Solution

In your backend you would include:

@Api(
  name = "myapi",
  version = "v1",
  clientIds = {Ids.WEB_CLIENT_ID, Ids.ANDROID_CLIENT_ID},
  audiences = {Ids.ANDROID_AUDIENCE}
)

Where those constants are defined as something like:

public class Ids {
  public static final String WEB_CLIENT_ID = "12345.apps.googleusercontent.com";
  public static final String ANDROID_CLIENT_ID = "12345-abc.apps.googleusercontent.com";
  public static final String ANDROID_AUDIENCE = WEB_CLIENT_ID;
}

Using the above values, the code you would use in your Android code is:

credential = GoogleAccountCredential.usingAudience(this,
    "server:client_id:" + Ids.ANDROID_AUDIENCE);

Problem

In the endpoints App Engine backend, how exactly do I set ``` @Api(name=... clientIds = {what-goes-here-exactly-1}, audiences = {what-goes-here-exactly-2} ) ``` and in the Android client, how exactly do I set ``` credential = GoogleAccountCredential.usingAudience(this, what-goes-here-exactly-3); ``` There are conflicting/confusing/unclear instructions here http://devthots.blogspot.com/ and here https://developers.google.com/appengine/docs/java/endpoints/consume_android#making-authenticated-calls I've generated lots of keys in my API Console's API Access, but not sure how to use them and append/prepend them for use in the above statements. Thanks.

Original source