vikassharma27 / google-api-translate-java

Automatically exported from code.google.com/p/google-api-translate-java
0 stars 0 forks source link

Why I am getting these exceptions? #172

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

I want to translate text file from one language(eg French) to other languages 
in java. I have written a code in java using google api and have used 
google-api-translate-java.jar. Below is my code

import java.util.Properties; import com.google.api.GoogleAPI; import 
com.google.api.translate.Language; import com.google.api.translate.Translate;

public class Translation { public static void main(String args) throws 
Exception {

Properties systemSettings = System.getProperties();

System.setProperty("http.proxySet", "true"); //Your proxy host server 
systemSettings.put("http.proxyHost","proxy") ; //Your proxy port 
systemSettings.put("http.proxyPort", "8080");
GoogleAPI.setHttpReferrer("http://code.google.com/p/google-api-translate-java");

GoogleAPI.setKey("i have set my Api key"); 
String translatedText = Translate.DEFAULT.execute("Bonjour le monde", 
Language.FRENCH, Language.ENGLISH); System.out.println(translatedText); } }

But I am getting following errors when I run it in eclipse:

Error: [google-api-translate-java] Error retrieving translation. Exception in 
thread "main" com.google.api.GoogleAPIException: java.lang.Exception: 
[google-api-translate-java] Error retrieving translation. at 
com.google.api.translate.TranslateV2?.execute(Trans lateV2.java:68) at 
Translation.main(Translation.java:15) Caused by: java.lang.Exception: 
[google-api-translate-java] Error retrieving translation. at 
com.google.api.GoogleAPI.retrieveJSON(GoogleAPI.ja va:99) at 
com.google.api.translate.TranslateV2?.execute(Trans lateV2.java:62) ... 1 more 
Caused by: java.io.IOException: Server returned HTTP response code: 403 for 
URL: https://www.googleapis.com/language/...t=en&source=fr at 
sun.reflect.NativeConstructorAccessorImpl?.newInsta nce0(Native Method) at 
sun.reflect.NativeConstructorAccessorImpl?.newInsta 
nce(NativeConstructorAccessorImpl?.java:57) at 
sun.reflect.DelegatingConstructorAccessorImpl?.newI 
nstance(DelegatingConstructorAccessorImpl?.java:45) at 
java.lang.reflect.Constructor.newInstance(Construc tor.java:532) at 
sun.net.www.protocol.http.HttpURLConnection$6.run( HttpURLConnection.java:1458) 
at java.security.AccessController?.doPrivileged(Native Method) at 
sun.net.http://www.protocol.http.HttpURLConn...ion.java:1452) at 
sun.net.http://www.protocol.http.HttpURLConn...ion.java:1106) at 
sun.net.http://www.protocol.https.HttpsURLCo...Impl.java:254) at 
com.google.api.GoogleAPI.retrieveJSON(GoogleAPI.ja va:93) ... 2 more Caused by: 
java.io.IOException: Server returned HTTP response code: 403 for URL: 
https://www.googleapis.com/language/...t=en&source=fr at 
sun.net.http://www.protocol.http.HttpURLConn...ion.java:1403) at 
sun.net.http://www.protocol.https.HttpsURLCo...Impl.java:254) at 
com.google.api.GoogleAPI.retrieveJSON(GoogleAPI.ja va:89) ... 2 more

Can anyone help me to resolve these error. I would be very thankful to you. 
Thanks in advance.

Original issue reported on code.google.com by anura.mo...@gmail.com on 25 Jul 2012 at 2:40

GoogleCodeExporter commented 8 years ago
I have seen this also, but I have noticed it generally happens once I have 
exceeded a certain amount of text to translate. Have you found any solutions.

Original comment by mike.oli...@gmail.com on 24 Oct 2012 at 7:31