首页 > 解决方案 > 带有谷歌文档 ai 的 api 密钥

问题描述

我正在使用谷歌文档 ai 的表单解析器。我发现的唯一身份验证方法是通过 gcloud 命令界面(“Authorization: Bearer”$(gcloud auth application-default print-access-token))。

我们的应用程序也使用 Google Vision,只需要一个 api 密钥 ( https://vision.googleapis.com/v1/images:annotate?key= )

我怎样才能使用这种方式谷歌文档AI?

我已经尝试使用 /apis/credentials 中的 api 密钥,并且我也尝试将密钥限制为 ip 并记录 ai api,但结果都相同:

curl -v -X POST -H "Content-Type: application/json; charset=utf-8" -d @request.json https://eu-documentai.googleapis.com/v1beta3/projects/<project id>/locations/eu/processors/<processor id>:process?key=<api key>

{
  "error": {
    "code": 401,
    "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "status": "UNAUTHENTICATED"
  }
}

我错过了什么?

标签: curlgoogle-apigoogle-oauth

解决方案


请求缺少所需的身份验证凭据。

表示您没有随请求发送任何授权

您尝试的请求要求您发送访问令牌作为不记名令牌

curl -H "Authorization: bearer <ACCESS_TOKEN>" http://www.example.com

您似乎只发送了一个 API 密钥,它只会授予您访问公共数据而非私人用户数据的权限。


推荐阅读