[英]Google Cloud Translate V3 Java - PERMISSION_DENIED: Cloud IAM permission 'cloudtranslate.generalModels.predict' denied
I have one project in google cloud, already using speech APIs successfully.我在谷歌云中有一个项目,已经成功地使用了语音 API。 I am the only user and I have Owner permissions over the service.
我是唯一的用户,我对该服务拥有所有者权限。 My account is connected to billing.
我的帐户已连接到帐单。 The environment credentials is set and working properly with other services.
环境凭据已设置并与其他服务一起正常工作。 I'm using Java SDK v3 (advanced translation).
我正在使用 Java SDK v3(高级翻译)。
When running translation in java I get PERMISSION_DENIED: Cloud IAM permission 'cloudtranslate.generalModels.predict' denied
.在 java 中运行翻译时,我得到
PERMISSION_DENIED: Cloud IAM permission 'cloudtranslate.generalModels.predict' denied
。
try (TranslationServiceClient client = TranslationServiceClient.create()) {
// projects/MY_PROJECT_ID/locations/global
LocationName parent = LocationName.of("MY_PROJECT_ID", "global");
// projects/MY_PROJECT_ID/locations/global/models/general/base
String model = parent.toString() + "/models/general/base";
TranslateTextRequest request =
TranslateTextRequest.newBuilder()
.setParent(parent.toString())
.setMimeType("text/plain")
.setSourceLanguageCode("he")
.setTargetLanguageCode("en")
.setModel(model)
.addContents(source)
.build();
TranslateTextResponse response = client.translateText(request);
for (Translation translation : response.getTranslationsList()) {
System.out.printf("Translated text: %s\n", translation.getTranslatedText());
}
}
Please advise:)请指教:)
So, you need to do this steps:因此,您需要执行以下步骤:
You need to create a service account in https://console.cloud.google.com/iam-admin/serviceaccounts Will be generated Email address for this account.你需要在https://console.cloud.google.com/iam-admin/serviceaccounts创建一个服务账号,会为这个账号生成Email地址。 Copy it.
复制它。
Make sure you have billing created and you have enabled the Google Translation API确保您已创建账单并启用了谷歌翻译 API
Next, you need to grant access rights to your new service account.接下来,您需要授予新服务帐户的访问权限。 IAM -> GRANT ACCESS -> Add Principle (this is your already copied email address from first step) -> Select a role (need to find "Cloud Translation API Admin")
IAM -> GRANT ACCESS -> Add Principle(这是你第一步已经复制的email地址) -> Select一个角色(需要找到“Cloud Translation API Admin”)
Rerun your application.重新运行您的应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.