如何设置clientIds和受众以对Android应用程序的Google Cloud Endpoints进行身份验证

时间:2013-03-07 12:54:45

标签: android google-cloud-endpoints

在端点App Engine后端,我该如何设置

@Api(name=...
     clientIds = {what-goes-here-exactly-1},
     audiences = {what-goes-here-exactly-2}
)

在Android客户端中,我该如何设置

credential = GoogleAccountCredential.usingAudience(this,
           what-goes-here-exactly-3);

这里有http://devthots.blogspot.com/https://developers.google.com/appengine/docs/java/endpoints/consume_android#making-authenticated-calls

的冲突/混淆/不明确说明

我在API控制台的API访问中生成了许多密钥,但不确定如何使用它们并附加/添加它们以用于上述语句。

感谢。

1 个答案:

答案 0 :(得分:6)

在你的后端你会包括:

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

这些常量定义为:

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;
}

使用上述值,您在Android代码中使用的代码为:

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