如何使用gcloud启用API

时间:2017-03-29 18:28:47

标签: google-cloud-platform gcloud

我无法找到使用this.$.myFile.inputElement.files[0]; 命令行程序来更改项目的Enabled API的方法。我的预感是,它将在计费“竞技场”,但我一直试图找到这个,并有很多运气。

5 个答案:

答案 0 :(得分:6)

Issue For your current default project do gcloud service-management list --enabled to list all available APIs enabled.

$ gcloud service-management list --enabled
Listed 0 items.

If you see something like the above i.e 0 items , then you most likely will be getting the error below for some commands for the project.

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

Solution What you need to do are the below

  1. list the APIs available for the project that can be enabled

The output is quite lengthy so I suggest you use the global option page-size e.g

$ 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

...
  1. Better still check specific available APIs you need e.g to check for the Google Compute Engine API that I want to enable

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

  2. Enable Billing for the project .

    $ 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. Finally enable the api for your project

`

$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

`

  1. And for good measure it won't hurt to verify

`

$ 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"
          }
        }

`

Caution Please note without the project being linked to a billing info , an attempt to enable the api will fail with an error similar to

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

答案 1 :(得分:5)

编辑:这已被弃用。请参阅gcloud services answer。

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

答案 2 :(得分:4)

使用

gcloud services enable <service name>

gcloud Documentation for this

示例:

gcloud services enable containerregistry.googleapis.com

答案 3 :(得分:1)

启用容器引擎API对我有用 -

gcloud services启用containerregistry.googleapis.com

答案 4 :(得分:1)

2021 年,改为

gcloud services list

enter image description here

详细信息为 here