如何使用gcloud启用API

the*_*her 10 google-cloud-platform gcloud

我无法找到使用gcloud命令行程序来更改项目的Enabled API的方法.我的预感是,它将在计费"竞技场"中,但我一直试图找到这个,并有很多运气.

小智 8

使用

gcloud services enable <service name>
Run Code Online (Sandbox Code Playgroud)

gcloud的相关文档

例:

gcloud services enable containerregistry.googleapis.com
Run Code Online (Sandbox Code Playgroud)


Abd*_*iyi 6

问题 对于当前的默认项目,请执行gcloud service-management list - 启用列出所有可用的API.

$ gcloud service-management list --enabled
Listed 0 items.
Run Code Online (Sandbox Code Playgroud)

如果你看到类似上面的东西,即0项,那么你很可能会得到以下错误的项目的一些命令.

ERROR: (gcloud.compute.machine-types.list) Some requests did not succeed:
 - Project {PROJECT_ID} is not found and cannot be used for API calls
Run Code Online (Sandbox Code Playgroud)

解决方案 您需要做的是以下内容

  1. 列出可以启用的项目可用的API

输出很长,所以我建议你使用全局选项页面大小,例如

$ gcloud service-management list  --available --page-size=10 --sort-by="NAME"
NAME                           TITLE
picker.googleapis.com          Google Picker API
bigquery-json.googleapis.com   BigQuery API
chromewebstore.googleapis.com  Chrome Web Store API
tracing.googleapis.com         Google Tracing API
youtube.googleapis.com         YouTube Data API v3
actions.googleapis.com         Google Actions API
dataflow.googleapis.com        Google Dataflow API
serviceuser.googleapis.com     Google Service User API
fusiontables.googleapis.com    Fusion Tables API
surveys.googleapis.com         Surveys API

NAME                                 TITLE
reseller.googleapis.com              Google Apps Reseller API
speech.googleapis.com                Google Cloud Speech API
appsmarket-component.googleapis.com  Google Apps Marketplace SDK
bigtabletableadmin.googleapis.com    Google Cloud Bigtable Table Admin API
container.googleapis.com             Google Container Engine API
vision.googleapis.com                Google Cloud Vision API
storage-api.googleapis.com           Google Cloud Storage JSON API
weavecompanion.googleapis.com        Weave Companion API
ml.googleapis.com                    Google Cloud Machine Learning Engine
firebaserules.googleapis.com         Firebase Rules API

...
Run Code Online (Sandbox Code Playgroud)
  1. 最好还是检查您需要的特定可用API,例如检查我想要启用的Google Compute Engine API

    $ gcloud service-management list --available --filter='NAME:compute*' NAME TITLE compute-component.googleapis.com Google Compute Engine API

  2. 为项目启用开票.

    $ gcloud alpha billing accounts projects link amghouse-some-project-1 --account-id=XXFFXX-B9XX37-2D5DX --format=json { "billingAccountName": "billingAccounts/XXFFXX-B9XX37-2D5DX", "billingEnabled": true, "name": "projects/amghouse-some-project-1 /billingInfo", "projectId": "amghouse-some-project-1 " }

  3. 最后为您的项目启用api

`

$gcloud service-management enable compute-component.googleapis.com
Waiting for async operation operations/projectSettings.c6d11ddc-915f-4d66-9b98-237e473e7682 to complete...
Operation finished successfully. The following command can describe the Operation details:
 gcloud service-management operations describe operations/projectSettings.c6d11ddc-915f-4d66-9b98-237e473e7682
Run Code Online (Sandbox Code Playgroud)

`

  1. 并且为了更好的衡量,验证不会有害

`

$ gcloud service-management operations describe operations/projectSettings.c6d11ddc-915f-4d66-9b98-237e473e7682 --format=json
        {
          "done": true,
          "metadata": {
            "@type": "type.googleapis.com/google.api.servicemanagement.v1.OperationMetadata",
            "persisted": true,
            "resourceNames": [
              "services/compute-component.googleapis.com/projectSettings/"
            ],
            "startTime": "2017-04-08 23:30:22 WAT"
          },
          "name": "operations/projectSettings.c6d11ddc-915f-4d66-9b98-237e473e7682",
          "response": {
            "@type": "type.googleapis.com/google.api.servicemanagement.v1.EnableServiceResponse"
          }
        }
Run Code Online (Sandbox Code Playgroud)

`

注意 请注意,如果没有将项目链接到计费信息,则尝试启用api将失败,并出现类似的错误

$ gcloud service-management enable compute-component.googleapis.com
ERROR: (gcloud.service-management.enable) FAILED_PRECONDITION: Operation does not satisfy the following requirements: billing-enabled {Billing must be enabled for activation of service '' in project 'amghouse-bct-sms-1' to proceed., https://console.developers.google.com/project/amghouse-bct-sms-1/settings}
Run Code Online (Sandbox Code Playgroud)


Val*_*tin 5

编辑:这已被弃用.见gcloud services答案.

看看service-management表面.有关gcloud help service-management更多帮助,请参阅gcloud help service-management enable有关启用新服务的帮助.使用gcloud service-management list列出可用的服务,让你可以找到你要启用的服务的名称.

  • "gcloud service-management"已被弃用,现在分为两个单独的命令 - "gcloud endpoints"和"gcloud services".后者(`gcloud services`)是用于为项目启用/禁用Google Cloud API的方法. (7认同)

Mic*_*lle 2

2021年,改为

gcloud services list
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

详细信息在这里