12

I read a couple of hours in the google docs about this but I still have no clue what I'm doing. I basically just want to use the google translation api to translate a few words that I had in mind. I have a valid account with billing details and I tried this code sample from google:


# Imports the Google Cloud client library
from google.cloud import translate

# Instantiates a client
translate_client = translate.Client()

# The text to translate
text = u'Hello, world!'
# The target language
target = 'ru'

# Translates some text into Russian
translation = translate_client.translate(
    text,
    target_language=target)

print(u'Text: {}'.format(text))
print(u'Translation: {}'.format(translation['translatedText']))

But it gives me this error: https://translation.googleapis.com/language/translate/v2?target=ru&q=Hello%2C+world%21 So I couldn't figute out how to include my API Key in Python, could anyone give me a quick help here, my head is exploding and I think I installed a lot of stuff that I don't need, like the Google Cloud SDK Shell and OAuth library for Python. Cheers

1 Answers1

1

You need to setup a env variable GOOGLE_APPLICATION_CREDENTIALS with the path to a json file with the api key as explained here https://cloud.google.com/translate/docs/setup?hl=en or set it in your code https://cloud.google.com/docs/authentication/production#passing_code

Gonzalo Odiard
  • 1,238
  • 12
  • 19