Results 1 to 2 of 2
  1. #1
    anuramoh is offline Member
    Join Date
    Jul 2012
    Posts
    1
    Rep Power
    0

    Default Language Translation using Google API

    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 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 {
    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 this error. I would be very thankful to you. Thanks in advance.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Language Translation using Google API

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Java Translation
    By hello_world in forum New To Java
    Replies: 6
    Last Post: 02-09-2012, 01:14 PM
  2. Language translation
    By archanaanbu in forum Java Applets
    Replies: 13
    Last Post: 02-19-2011, 07:56 PM
  3. Language translation
    By archanaanbu in forum Java Applets
    Replies: 0
    Last Post: 02-09-2011, 06:21 AM
  4. problem in google-gwt language api class method??
    By narasimhavsi in forum Java Software
    Replies: 1
    Last Post: 02-09-2010, 03:59 PM
  5. WORD Translation HELP PLZ :(
    By sammypants in forum New To Java
    Replies: 2
    Last Post: 11-24-2009, 02:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •