如何启用 Google Vision API 在同一项目中访问 Google Cloud Storage Bucket [英] How to enable Google Vision API to access Google Cloud Storage Bucket within same project

查看:19
本文介绍了如何启用 Google Vision API 在同一项目中访问 Google Cloud Storage Bucket的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将一些测试图像上传到 Google Cloud Bucket,但不想将它们公开(这会作弊).当我尝试为 Google Vision API 运行休息调用时,我得到:

I have uploaded some test images to a Google Cloud Bucket, but don't want to make them public (which would be cheating). When I try to run a rest call for Google Vision API I get:

{
  "responses": [
    {
      "error": {
        "code": 7,
        "message": "image-annotator::User lacks permission.: Can not open file: gs://images-translate-156512/P1011234.JPG"
      }
    }
  ]
}

启用 Google Vision API 访问同一项目中的 Google Cloud Storage 对象的步骤是什么?目前,我在试验 Google Vision 时只使用 API 密钥.我怀疑可能需要服务帐户和 GCS 对象上的 ACL.

What are the steps to enable the Google Vision API to access Google Cloud Storage objects within the same project? At the moment I am using only the API key while I experiment with Google Vision. I am suspecting a service account may be required and an ACL on the GCS objects.

我可以完全绕过 GCS 并对图像进行 base64 编码并将其发送到 Google Vision API,但我真的很想尝试解决这个用例.尚未使用 ACL 或服务帐户.

I could bypass GCS altogether and base64 encode the image and send it Google Vision API, but really want to try and solve this use case. Not used ACLs yet, or service accounts.

任何帮助表示赞赏

推荐答案

API 密钥不用于授权.它们用于您要指定应为某个操作计费的项目以及应使用哪个项目的配额的情况,但它们不会将您作为任何特定实体进行身份验证.

API keys are not used for authorization. They are used in situations where you want to specify which project should be billed for an operation and which project's quota should be used, but they do not authenticate you as any particular entity.

要将 Cloud Vision API 与非公共 GCS 对象一起使用,您需要发送 OAuth 身份验证信息以及您对有权读取 GCS 对象的用户或服务帐户的请求.

In order to use the Cloud Vision API with a non-public GCS object, you'll need to send OAuth authentication information along with your request for a user or service account which has permission to read the GCS object.

授权是一个复杂的话题.我建议使用 gcloud 命令行实用程序进行临时实验或使用 Google Cloud 客户端库来开发您所使用的语言.

Authorization is a complex topic. I recommend using the gcloud command-line utility for ad-hoc experimentation or the Google Cloud client library for the language you're developing in.

Google 在此处提供了授权指南:https://cloud.google.com/docs/authentication

Google has a guide for authorization here: https://cloud.google.com/docs/authentication

这篇关于如何启用 Google Vision API 在同一项目中访问 Google Cloud Storage Bucket的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆