vikassharma27 / google-api-translate-java

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

Server returned HTTP response code: 403 #191

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I am trying to run the example code for the google api translate in java 
http://code.google.com/p/google-api-translate-java/
However I get an Error: [google-api-translate-java] Error retrieving 
translation.
I have set up my api key and added my ip in the dev console. I can see request 
in the traffic report, am I missing something?

import java.util.Properties;
import com.google.api.GoogleAPI;
import com.google.api.translate.Language;
import com.google.api.translate.Translate;
public class test
{
  public static void main(String[] args) throws Exception
  {
    // Set proxy
    Properties systemSettings = System.getProperties();
    System.setProperty("http.proxyHost", "proxy");
    System.setProperty("http.proxyPort", "8080");
    System.setProperties(systemSettings);

    // Set the HTTP referrer to your website address.
    GoogleAPI.setHttpReferrer("https://www.mc3.edu");

    // Set the Google Translate API key
    // See: http://code.google.com/apis/language/translate/v2/getting_started.html
    GoogleAPI.setKey("API key");

    String translatedText = Translate.DEFAULT.execute("Bonjour le monde", Language.FRENCH, Language.ENGLISH);

    System.out.println(translatedText);
  }
}

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(TranslateV2.java:68)
    at test.main(test.java:23)
Caused by: java.lang.Exception: [google-api-translate-java] Error retrieving 
translation.
    at com.google.api.GoogleAPI.retrieveJSON(GoogleAPI.java:99)
    at com.google.api.translate.TranslateV2.execute(TranslateV2.java:62)
    ... 1 more
Caused by: java.io.IOException: Server returned HTTP response code: 403 for 
URL: 
https://www.googleapis.com/language/translate/v2?key=AIzaSyCsD6bZtsO-gcBFGJa-48v
2qSiOvJfco14&q=Bonjour+le+monde&target=en&source=fr
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection$6.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.net.www.protocol.http.HttpURLConnection.getChainedException(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
    at com.google.api.GoogleAPI.retrieveJSON(GoogleAPI.java:93)
    ... 2 more
Caused by: java.io.IOException: Server returned HTTP response code: 403 for 
URL: 
https://www.googleapis.com/language/translate/v2?key=AIzaSyCsD6bZtsO-gcBFGJa-48v
2qSiOvJfco14&q=Bonjour+le+monde&target=en&source=fr
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
    at com.google.api.GoogleAPI.retrieveJSON(GoogleAPI.java:89)
    ... 2 more

Original issue reported on code.google.com by Darkange...@gmail.com on 31 Mar 2014 at 6:26