【发布时间】:2021-11-18 06:29:41
【问题描述】:
我正在尝试从本地机器(不是谷歌云)使用谷歌翻译 API。
在运行以下之前我已经运行
export GOOGLE_APPLICATION_CREDENTIALS=API.json
API.json 在哪里:
{ "key":"the_key_code" }
运行这段代码后:
import google.auth
from google.cloud import translate
_, PROJECT_ID = google.auth.default()
TRANSLATE = translate.TranslationServiceClient()
我收到以下错误:
DefaultCredentialsError: The file API_.json does not have a valid type. Type is None, expected one of ('authorized_user', 'service_account', 'external_account')
然后我在 json 中添加了 type: service_account 并得到了这个错误:
DefaultCredentialsError: ('Failed to load service account credentials from API.json', ValueError('Service account info was not in the expected format, missing fields client_email, token_uri.'))
我找不到任何关于 API 密钥 json 文件格式的文档,也无法从谷歌云平台导出 json 文件,只能复制密钥。
关于如何从本地机器翻译工作的任何想法?
【问题讨论】:
标签: json google-translate