【发布时间】:2013-08-13 07:17:01
【问题描述】:
我使用Google Translate API's Get Started中的以下代码
<head>
<title>Translate API Example</title>
</head>
<body>
<div id="sourceText">Hello world</div>
<div id="translation"></div>
<script>
function translateText(response) {
// ERROR SHOW HERE
document.getElementById("translation").innerHTML += "<br>" + response.data.translations[0].translatedText;
}
</script>
<script>
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
var sourceText = escape(document.getElementById("sourceText").innerHTML);
var source = 'https://www.googleapis.com/language/translate/v2?key=MY-KEY&source=en&target=de&callback=translateText&q=' + sourceText;
newScript.src = source;
// When we add this script to the head, the request is sent off.
document.getElementsByTagName('head')[0].appendChild(newScript);
</script>
</body>
我收到错误 "TypeError: Cannot read property 'translations' of undefined"
请告诉我如何解决这个错误,
谢谢,
【问题讨论】:
-
您是否提供了 API 密钥?
标签: python google-translate google-api-python-client