作者:zjymeimei706 | 来源:互联网 | 2023-02-08 10:32
我无法找到使用gcloud
命令行程序来更改项目的Enabled API的方法.我的预感是,它将在计费"竞技场"中,但我一直试图找到这个,并有很多运气.
1> 小智..:
使用
gcloud services enable
gcloud的相关文档
例:
gcloud services enable containerregistry.googleapis.com
2> Abdurrahman ..:
问题
对于当前的默认项目,请执行gcloud service-management list - 启用列出所有可用的API.
$ gcloud service-management list --enabled
Listed 0 items.
如果你看到类似上面的东西,即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
解决方案
您需要做的是以下内容
列出可以启用的项目可用的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
...
最好还是检查您需要的特定可用API,例如检查我想要启用的Google Compute Engine API
$ gcloud service-management list --available --filter='NAME:compute*'
NAME TITLE
compute-component.googleapis.com Google Compute Engine API
为项目启用开票.
$ 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 "
}
最后为您的项目启用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
`
并且为了更好的衡量,验证不会有害
`
$ 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"
}
}
`
注意
请注意,如果没有将项目链接到计费信息,则尝试启用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}
3> Valentin..:
编辑:这已被弃用.见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的方法.