服务器返回 HTTP 响应代码:403 for URL Google Translate API
Server returned HTTP response code: 403 for URL Google Translate API
我正在使用 google 将 api 翻译成 Java。
当我尝试从代码中获取翻译时,出现以下错误:
java.io.IOException: Server returned HTTP response code: 403 for URL: http://translate.google.com.br/translate_a/single?client=t&sl=auto&tl=pt&hl=en&dt=bd&dt=ex&dt=ld&dt=md&dt=qc&dt=rw&dt=rm&dt=ss&dt=t&dt=at&ie=UTF-8&oe=UTF-8&otf=1&rom=1&ssel=0&tsel=3&kc=1&tk=620730|996163&q=Try%20mWinMgr%20=%20(WindowManager)context.getSystemService(Context.WINDOW_SERVICE);int%20displayWidth%20=%20mWinMgr.getDefaultDisplay().getWidth();where%20context%20is%20Context%20instance.By%20default,%20the%20FrameLayout%20in%20which%20your%20layout%20is%20kept,%20fills%20the%20whole%20display%20horizontally%20(vertically%20you%20can%20have%20status%20bar).%20So%20you%20can%20set%20the%20maximum%20possible%20width%20by%20using%20android:layout_width="fill_parent"%20correctly.
我的 url 连接对象定义为:
urlConn = url.openConnection();
urlConn.addRequestProperty("User-Agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
有什么建议吗?
API 使用代码:
translate.translate(text, Language.ENGLISH,
Language.PORTUGUESE);
仅在上周发生错误。
在此之前,使用相同的代码一切正常
生成的 URL 看起来格式不正确。您正在使用的库也是来自 Google 代码 archive 的过时库。它可能是巧合,但你现在暴露了一个问题。
请使用当前版本的翻译 API 客户端,可用 here。
试试这个,使用更新的 API(你需要一个密钥):http://hayageek.com/google-translate-api-tutorial/#java-example
我正在使用 google 将 api 翻译成 Java。
当我尝试从代码中获取翻译时,出现以下错误:
java.io.IOException: Server returned HTTP response code: 403 for URL: http://translate.google.com.br/translate_a/single?client=t&sl=auto&tl=pt&hl=en&dt=bd&dt=ex&dt=ld&dt=md&dt=qc&dt=rw&dt=rm&dt=ss&dt=t&dt=at&ie=UTF-8&oe=UTF-8&otf=1&rom=1&ssel=0&tsel=3&kc=1&tk=620730|996163&q=Try%20mWinMgr%20=%20(WindowManager)context.getSystemService(Context.WINDOW_SERVICE);int%20displayWidth%20=%20mWinMgr.getDefaultDisplay().getWidth();where%20context%20is%20Context%20instance.By%20default,%20the%20FrameLayout%20in%20which%20your%20layout%20is%20kept,%20fills%20the%20whole%20display%20horizontally%20(vertically%20you%20can%20have%20status%20bar).%20So%20you%20can%20set%20the%20maximum%20possible%20width%20by%20using%20android:layout_width="fill_parent"%20correctly.
我的 url 连接对象定义为:
urlConn = url.openConnection();
urlConn.addRequestProperty("User-Agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
有什么建议吗?
API 使用代码:
translate.translate(text, Language.ENGLISH,
Language.PORTUGUESE);
仅在上周发生错误。 在此之前,使用相同的代码一切正常
生成的 URL 看起来格式不正确。您正在使用的库也是来自 Google 代码 archive 的过时库。它可能是巧合,但你现在暴露了一个问题。
请使用当前版本的翻译 API 客户端,可用 here。
试试这个,使用更新的 API(你需要一个密钥):http://hayageek.com/google-translate-api-tutorial/#java-example