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

查看:152
本文介绍了如何启用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天全站免登陆