【发布时间】:2021-03-18 13:49:30
【问题描述】:
我正在尝试将 Cloud Natural Language API 与此链接中给出的代码一起使用。 (第一或第二) link
我收到以下错误。
google.api_core.exceptions.PermissionDenied: 403 Your application has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are nots
upported by the language.googleapis.com. We recommend configuring the billing/quota_project setting in gcloud or using a service account through the auth/impersonate_service
_account setting. For more information about service accounts and how to use them in your application, see https://cloud.google.com/docs/authentication/.
我知道我们需要按照 google doc (link) 在代码中提供服务帐户密钥的 json 文件。但它并没有说明处理 API 密钥。也不建议在代码中提供 API Key。那么方法是什么呢?
我尝试使用带有 API 密钥的 Curl 命令,它工作正常。
curl "https://language.googleapis.com/v1/documents:analyzeEntities?key=${API_KEY}" -s -X POST -H "Content-Type: applicat
ion/json" --data-binary @request.json
但是我不知道如何将 API 密钥(我拥有的)合并到我上面发布的第一个链接中的代码中。
【问题讨论】:
-
你在使用一些 SKD 吗?您使用哪种语言?
-
@R.Esteves 我正在使用 Python。我从启用了 NLP API 的同一个项目中打开了一个 cloudshell 编辑器。
-
您是否尝试将
os.eviron['GOOGLE_APPLICATION_CREDENTIALS'] = "/path/to/json/file"放在代码的开头?
标签: google-cloud-platform google-api google-cloud-automl