我在google文档中阅读了几个小时的内容,但是我仍然不知道自己在做什么。我基本上只是想使用google translation api翻译我想到的几个单词。我有一个具有帐单明细的有效帐户,并且尝试了以下来自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']))
Run Code Online (Sandbox Code Playgroud)
但这给了我这个错误:https : //translation.googleapis.com/language/translate/v2?target = ru&q = Hello%2C+world%21因此,我无法弄清楚如何在Python中包含我的API密钥,谁能在这里给我快速帮助,我的脑袋爆炸了,我想我安装了很多我不需要的东西,例如Google Cloud SDK Shell和Python的OAuth库。干杯
您需要设置一个环境变量 GOOGLE_APPLICATION_CREDENTIALS ,其中包含带有 api 密钥的 json 文件的路径,如此处所述https://cloud.google.com/translate/docs/setup?hl=en或在代码中设置它https:// /cloud.google.com/docs/authentication/development#passing_code
归档时间: |
|
查看次数: |
590 次 |
最近记录: |