我尝试使用此链接中的解决方案:How to use Google Translate API in my Java application?
代码:
Translator translate = Translator.getInstance();
String text = translate.translate("Hello!", Language.ENGLISH, Language.ROMANIAN);
System.out.println(text); // "Bună ziua!"
但我的代码中出现以下错误:
ava.io.IOException: Server returned HTTP response code: 403 for URL: http://translate.google.com.br/translate_a/t?client=t&text=I%20am%20programmer&hl=en&sl=en&tl=pt&multires=1&prev=btn&ssel=0&tsel=0&sc=1
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1876)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
at com.gtranslate.utils.WebUtils.source(WebUtils.java:24)
at com.gtranslate.parsing.ParseTextTranslate.parse(ParseTextTranslate.java:19)
at com.gtranslate.Translator.translate(Translator.java:37)
at gotranslate.GoTranslate.main(GoTranslate.java:14)
答案 0 :(得分:0)
以前使用Google工具的所有库都被屏蔽,使用它们的唯一方法是使用Google云端平台:
Google returned the following error: [403] Please use Translate v2. See http://code.google.com/apis/language/translate/overview.html