我一直在下面发布的代码来音译用户点击按钮时的输入。但是当运行代码并单击音译按钮时,我在浏览器(火狐(控制台中得到/* callback */google.language.callbacks.id100('22', null, 403, 'This API is no longer available.', 200)
响应。那么请告诉它的替代解决方案是什么?
法典:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google AJAX Language API - Basic Transliteration</title>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("language", "1");
google.load("elements", "1", { packages: "transliteration" });
function intialize_transliteration(){
var options = {
sourceLanguage: 'en',
destinationLanguage: ['kn'],
shortcutKey: 'ctrl+g',
transliterationEnabled: true
};
var control =
new google.elements.transliteration.TransliterationControl(options);
//add as many as required
var ids = [ "fnk", "lnk" ];
control.makeTransliteratable(ids);
control.showControl('translControl');
}
google.setOnLoadCallback(intialize_transliteration);
function tr() {
//Call google.language.transliterate()
google.language.transliterate(["asdas"], "en", "ur", function(result) {
var container = document.getElementById("fnk");
if (result.transliterations && result.transliterations.length > 0 &&
result.transliterations[0].transliteratedWords.length > 0) {
container.innerHTML = result.transliterations[0].transliteratedWords[0];
}
});
}
</script>
</head>
<body>
<br> First Name <input value="Thejesh Gangaiah" id="fn" />
<br> First Name (in Kannada) <input value="" id="fnk"/>
<br> Last Name <input value="Nagarathna" id="ln" />
<br> Last Name (in Kannada) <input value="" id="lnk"/>
<div id='translControl'></div>
<input type="button" onclick="tr()" value="transliterate"/>
</body>
</html>
谷歌音译 API 在 2011 年被弃用,所以我认为,从今天(2018 年 6 月(起,根据他们的弃用政策,它可以消失。这意味着不能再使用了。问题不在于您的代码,而在于服务变得不可用。