什么是Google Cloud Endpoints的Web应用程序客户端ID?

时间:2013-02-19 23:32:32

标签: google-app-engine google-cloud-endpoints

我想让示例android client起作用。

我被困在设置说明的第4步:

  

更新src / com / google / devrel / samples / ttt / ClientCredentials.java中的AUDIENCE值,将字符串“your_web_client_id”替换为您在API控制台中注册的Web应用程序客户端ID。

以下是我需要更改的代码行:

public static final String AUDIENCE = "server:client_id:your_web_client_id";

我不确定“Web应用程序客户端ID”的含义。我在GAE上运行了Java后端,但没有使用API​​控制台做任何事情。

有什么想法吗?


修改

这是java后端的客户端ID代码:

/**
 * Contains the client IDs for allowed clients consuming the tictactoe API.
 */
public class Ids {
  public static final String WEB_CLIENT_ID = "240003018828.apps.googleusercontent.com";
  public static final String ANDROID_CLIENT_ID = "240003018828-rp5ahj5b1eo76g55m1qtq4vvm57dqoj6.apps.googleusercontent.com";
  public static final String IOS_CLIENT_ID = "replace this with your iOS client ID";
  public static final String ANDROID_AUDIENCE = WEB_CLIENT_ID;
}

这是android项目中的客户端ID代码:

public class ClientCredentials
{
    public static final String AUDIENCE = "server:client_id:240003018828-rp5ahj5b1eo76g55m1qtq4vvm57dqoj6.apps.googleusercontent.com";
    // public static final String AUDIENCE = "server:client_id:your_web_client_id";
}

还来自android项目:

  /**
   * The default encoded root URL of the service. This is determined when the library is generated
   * and normally should not be changed.
   *
   * @since 1.7
   */
  public static final String DEFAULT_ROOT_URL = "https://sample-ttt.appspot.com/_ah/api/";

2 个答案:

答案 0 :(得分:4)

请参阅Android终端文档的Making Authenticated Calls部分。

  

在项目的Google API Console中添加第二个客户端ID。至   这样做:

     
      
  1. 在控制台内项目的API Access选项卡中,单击Create another client ID。
  2.   
  3. 列表项
  4.   
  5. 在“创建客户端ID”表单中,为应用程序类型选择“已安装的应用程序”,为已安装的应用程序类型选择“Android”。
  6.   
  7. 在标有包名称的文本框中输入您的Android应用程序包名称。
  8.   
  9. 在标记为签名证书指纹的文本框中,输入您刚刚生成的调试或释放密钥。
  10.   
  11. 单击“创建客户端ID”。
  12.   

它说的是第二个客户端ID,因为您还需要为Web应用程序创建一个。在流程结束时,您应该有两个客户端ID:一个用于Android,一个用于Web。您在后端代码中使用两个客户端ID,但在Android代码中仅包含后一个客户端ID(通过特殊格式的字符串)。

答案 1 :(得分:1)

您是否使用网络应用程序ID更新了应用引擎后端的AUDIENCE字段?要从Android客户端使用GCE,您需要在@Api注释中更新Audience字段,使用Web应用程序ID(不是android客户端ID),您已在API控制台中注册。