OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

PERMISSION_DENIED: Cloud IAM permission 'cloudtranslate.generalModels.predict' denied

  • Thread starter Thread starter Felix Schmidt
  • Start date Start date
F

Felix Schmidt

Guest
I'm trying to figure out how the google translate API works. I have little experience with google cloud api.

I'm getting this error: PERMISSION_DENIED: Cloud IAM permission 'cloudtranslate.generalModels.predict' denied.

My questions:

  1. Why do I need this permission? I am setting source and target language in my code. There is actually nothing to perdict.
  2. How to get this solved? I assume based on related questions that I have to give my service account these permissions, but I haven't figured out how to do this in the console. In the service account tab I cannot link permissions. In the roles tab I created a role with these permissions, but I wasn't able to link it to my service account.

Code:
try (TranslationServiceClient client = TranslationServiceClient.create()) {
            // Supported Locations: `global`, [glossary location], or [model location]
            // Glossaries must be hosted in `us-central1`
            // Custom Models must use the same location as your model. (us-central1)
            LocationName parent = LocationName.of(projectId, "global");
            // Supported Mime Types: https://cloud.google.com/translate/docs/supported-formats
            TranslateTextRequest request =
                    TranslateTextRequest.newBuilder()
                            .setParent(parent.toString())
                            .setMimeType("text/plain")
                            .setTargetLanguageCode("de")
                            .setSourceLanguageCode("en")
                            .addContents("Hello World")
                            .build();
            TranslateTextResponse response = client.translateText(request);
            // Display the translation for each input text provided
            for (Translation translation : response.getTranslationsList()) {
                System.out.printf("Translated text: %s\n", translation.getTranslatedText());
            }
        }
<p>I'm trying to figure out how the google translate API works. I have little experience with google cloud api.</p>
<p>I'm getting this error: PERMISSION_DENIED: Cloud IAM permission 'cloudtranslate.generalModels.predict' denied.</p>
<p>My questions:</p>
<ol>
<li>Why do I need this permission? I am setting source and target language in my code. There is actually nothing to perdict.</li>
<li>How to get this solved? I assume based on related questions that I have to give my service account these permissions, but I haven't figured out how to do this in the console. In the service account tab I cannot link permissions. In the roles tab I created a role with these permissions, but I wasn't able to link it to my service account.</li>
</ol>
<pre><code>try (TranslationServiceClient client = TranslationServiceClient.create()) {
// Supported Locations: `global`, [glossary location], or [model location]
// Glossaries must be hosted in `us-central1`
// Custom Models must use the same location as your model. (us-central1)
LocationName parent = LocationName.of(projectId, "global");
// Supported Mime Types: https://cloud.google.com/translate/docs/supported-formats
TranslateTextRequest request =
TranslateTextRequest.newBuilder()
.setParent(parent.toString())
.setMimeType("text/plain")
.setTargetLanguageCode("de")
.setSourceLanguageCode("en")
.addContents("Hello World")
.build();
TranslateTextResponse response = client.translateText(request);
// Display the translation for each input text provided
for (Translation translation : response.getTranslationsList()) {
System.out.printf("Translated text: %s\n", translation.getTranslatedText());
}
}
</code></pre>
Continue reading...
 
Top