我正在为一个项目使用 Cloud Vision API,并且我正在尝试构建并运行 quickstart 示例,但我收到以下错误:
google::cloud::Status thrown: PERMISSION_DENIED: Error in non-idempotent operation: Your application is authenticating by using local Application Default Credentials.
The vision.googleapis.com API requires a quota project, which is not set by default.
To learn how to set your quota project, see https://cloud.google.com/docs/authentication/adc-troubleshooting/user-creds .
error_info={reason=SERVICE_DISABLED, domain=googleapis.com, metadata={gcloud-cpp.retry.reason=non-idempotent,
gcloud-cpp.retry.original-message=Your application is authenticating by using local Application Default Credentials.
The vision.googleapis.com API requires a quota project, which is not set by default.
To learn how to set your quota project, see https://cloud.google.com/docs/authentication/adc-troubleshooting/user-creds .,
consumer=projects/764086051850, gcloud-cpp.retry.function=BatchAnnotateImages, service=vision.googleapis.com}}
我跑了
gcloud auth applicataion-default set-quota-project [project-id]
几次,有多个不同的项目,但无济于事。
这是怎么回事?
这个错误信息
您的应用程序正在使用本地应用程序默认凭据进行身份验证。 Vision.googleapis.com API 需要配额项目,默认情况下未设置。要了解如何设置配额项目,请参阅 https://cloud.google.com/docs/authentication/adc-troubleshooting/user-creds ...
...不是真的,但也不是完全没有帮助。
在使用 Identitytoolkit.googleapis.com 直接调用 REST API(而不是通过库)时,我收到了类似的错误消息。只需使用curl等即可。
我从
gcloud auth print-access-token
获取了我的令牌,因此错误消息“您的应用程序正在使用本地应用程序默认凭据进行身份验证。”显然是错误的。
以及“vision.googleapis.com API 需要配额项目,默认情况下未设置。”也错了。对我来说,和你一样,即使在按照建议的步骤
为 ADC 设置了配额项目之后gcloud auth applicataion-default set-quota-project [project-id]
..它仍然给出相同的错误消息。对你来说有好处,在投降之前多次尝试同一件事。我也这么做了。但实际上,我们应该知道它行不通,因为我们一开始就没有使用 ADC。
但这并不是完全没有帮助,因为它谈论的是计费。
解决方案在此处描述,在解释如何对 ADC 进行故障排除的文档中
Google Cloud API 有两种:Vision 和 Identitytoolkit 是由客户付费的 API,因此如果您要直接使用 API,则需要使用基于资源的 API,使用与正在访问的资源关联的项目来进行计费和配额。
基于客户端的 API,使用与访问资源的帐户关联的项目来进行计费和配额。
当您提供用户凭据以向基于客户端的 API 进行身份验证时,您必须指定用于计费和配额的项目。这个项目称为配额项目。
有多种方法可以指定配额项目,包括以下选项:
- 更新 ADC 以使用不同的项目作为配额项目:
gcloud auth application-default set-quota-project YOUR_PROJECT
- 如果您直接调用 REST 或 RPC API,请
使用 x-goog-user-project HTTP 标头在每个请求中指定配额项目。有关详细信息,请参阅使用 REST 请求设置配额项目。
X-goog-user-project 标头。
您可能会问,为什么调用具有特殊计费要求的 REST API,仅在文档页面中进行了描述 ADC 故障排除”?我告诉你,这太邪恶了。这就像告诉人们阅读洗碗机上的文档以了解如何启动汽车一样。tl;博士。
错误信息是错误的。该文档是对的,但位置错误。如果错误消息直接重定向到此 stackoverflow 线程会更好。