Server returned HTTP response code: 403 for URL Google Translate API

橙三吉。 提交于 2019-12-19 09:56:27

问题


i'm using google translate api for Java.
When i'm tried to get translate from code i got the following error:

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.

My url conntection object is define:

urlConn = url.openConnection();

urlConn.addRequestProperty("User-Agent",
                "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");

Any suggestions please?

API Using code:

translate.translate(text, Language.ENGLISH,
            Language.PORTUGUESE);

An error occurred only in the last week. Before that everything works fine with the same code


回答1:


Try this, using the updated API (you need a key): http://hayageek.com/google-translate-api-tutorial/#java-example




回答2:


It looks like the URL being generated is malformed. The library you are using is also an out-of-date library from the Google Code archive. It likely was working by coincidence, but you just now exposed a problem.

Please use the current version of the Translate API Client, available here.



来源:https://stackoverflow.com/questions/35182285/server-returned-http-response-code-403-for-url-google-translate-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!