Service Management API 使用入门

本页描述如何设置开发环境来使用 Service Management API。使用 Service Management API 的最简单方法(不仅仅是使用 Google Cloud 控制台 网络界面),对于大多数操作用例,我们的建议是通过 gcloud 命令行接口。如果您需要针对 Service Management API 进行编程,则可以使用我们提供的某一客户端库。若要试用该 API,您可以按照下面的备用设置说明进行操作,并使用 curl 命令来使用该 API,而无需设置完整的应用开发环境。

使用 gcloud 进行设置

  1. 登录您的 Google Cloud 账号。如果您是 Google Cloud 新手,请创建一个账号来评估我们的产品在实际场景中的表现。新客户还可获享 $300 赠金,用于运行、测试和部署工作负载。
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Enable the Service Management API.

    Enable the API

  4. Install the Google Cloud CLI.
  5. To initialize the gcloud CLI, run the following command:

    gcloud init
  6. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  7. Enable the Service Management API.

    Enable the API

  8. Install the Google Cloud CLI.
  9. To initialize the gcloud CLI, run the following command:

    gcloud init

设置为直接调用 API

本节描述了通过使用 curl 命令的 Service Management API 设置本地环境以进行试验所必需的基本步骤。这种设置适用于需要针对 Service Management API 进行编程的开发者。

初始设置

  1. 登录您的 Google Cloud 账号。如果您是 Google Cloud 新手,请创建一个账号来评估我们的产品在实际场景中的表现。新客户还可获享 $300 赠金,用于运行、测试和部署工作负载。
  2. Install the Google Cloud CLI.
  3. To initialize the gcloud CLI, run the following command:

    gcloud init
  4. Create or select a Google Cloud project.

    • Create a Google Cloud project:

      gcloud projects create PROJECT_ID

      Replace PROJECT_ID with a name for the Google Cloud project you are creating.

    • Select the Google Cloud project that you created:

      gcloud config set project PROJECT_ID

      Replace PROJECT_ID with your Google Cloud project name.

  5. Enable the Service Management API:

    gcloud services enable servicemanagement.googleapis.com
  6. Grant roles to your user account. Run the following command once for each of the following IAM roles: roles/servicemanagement.admin

    gcloud projects add-iam-policy-binding PROJECT_ID --member="USER_IDENTIFIER" --role=ROLE
    • Replace PROJECT_ID with your project ID.
    • Replace USER_IDENTIFIER with the identifier for your user account. For example, user:myemail@example.com.

    • Replace ROLE with each individual role.
  7. Install the Google Cloud CLI.
  8. To initialize the gcloud CLI, run the following command:

    gcloud init
  9. Create or select a Google Cloud project.

    • Create a Google Cloud project:

      gcloud projects create PROJECT_ID

      Replace PROJECT_ID with a name for the Google Cloud project you are creating.

    • Select the Google Cloud project that you created:

      gcloud config set project PROJECT_ID

      Replace PROJECT_ID with your Google Cloud project name.

  10. Enable the Service Management API:

    gcloud services enable servicemanagement.googleapis.com
  11. Grant roles to your user account. Run the following command once for each of the following IAM roles: roles/servicemanagement.admin

    gcloud projects add-iam-policy-binding PROJECT_ID --member="USER_IDENTIFIER" --role=ROLE
    • Replace PROJECT_ID with your project ID.
    • Replace USER_IDENTIFIER with the identifier for your user account. For example, user:myemail@example.com.

    • Replace ROLE with each individual role.

用 curl 进行测试

  1. 为调用 Google REST API 定义一个方便的 shell 别名:

    $ alias gcurl='curl -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json"'
    
  2. 尝试列出公共可访问服务:

    $ gcurl https://servicemanagement.googleapis.com/v1/services
    

    如果您看到服务列表,则说明设置成功。

后续步骤

如果您要创建托管式服务但没有使用 Cloud Endpoints,请按照下列步骤操作:

  1. 按照创建和删除服务来创建托管式服务。这将创建一个顶级托管式服务资源。
  2. 按照管理服务配置中的说明提交服务配置,以描述该服务所使用的功能。

  3. 按照发布服务配置中的说明来发布您的服务配置。