如何在Python中使用API密钥,使用Google翻译API。

12

我在谷歌文档上读了几个小时,但我仍然不知道我在做什么。 我基本上只想使用谷歌翻译API来翻译我心中想到的几个单词。 我有一个有效的带有计费详细信息的帐户,并尝试了谷歌提供的这个代码示例:


# 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']))

但是它给了我这个错误:https://translation.googleapis.com/language/translate/v2?target=ru&q=Hello%2C+world%21 所以我无法弄清楚如何在Python中包含我的API密钥,有人能帮我快速解决一下吗?我的脑袋要爆炸了,我觉得我安装了很多我不需要的东西,比如Google Cloud SDK Shell和Python的OAuth库。 谢谢!
1个回答

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接