本页描述如何设置开发环境来使用 Service Management API。使用 Service Management API 的最简单方法(不仅仅是使用 Google Cloud 控制台 网络界面),对于大多数操作用例,我们的建议是通过 gcloud
命令行接口。如果您需要针对 Service Management API 进行编程,则可以使用我们提供的某一客户端库。若要试用该 API,您可以按照下面的备用设置说明进行操作,并使用 curl
命令来使用该 API,而无需设置完整的应用开发环境。
使用 gcloud 进行设置
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Enable the Service Management API.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Enable the Service Management API.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
设置为直接调用 API
本节描述了通过使用 curl
命令的 Service Management API 设置本地环境以进行试验所必需的基本步骤。这种设置适用于需要针对 Service Management API 进行编程的开发者。
初始设置
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
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.
-
-
Enable the Service Management API:
gcloud services enable servicemanagement.googleapis.com
-
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: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.
- Replace
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
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.
-
-
Enable the Service Management API:
gcloud services enable servicemanagement.googleapis.com
-
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: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.
- Replace
用 curl 进行测试
为调用 Google REST API 定义一个方便的 shell 别名:
$ alias gcurl='curl -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json"'
尝试列出公共可访问服务:
$ gcurl https://servicemanagement.googleapis.com/v1/services
如果您看到服务列表,则说明设置成功。
后续步骤
如果您要创建托管式服务但没有使用 Cloud Endpoints,请按照下列步骤操作: