Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android google translate API

I have a problem with receiving translations from Google via translate API. Does somebody know what is wrong? Thanks!

Note: It has worked fine for some time but maybe 5 months ago it stopped to work.

@Override
public void onClick(View v) {
    GoogleAPI.setHttpReferrer("http://code.google.com/p/google-api-translate-java/");
    GoogleAPI.setKey("xxx");

    try {
        tv_answer.setText(Translate.DEFAULT.execute(tv_source.getText().toString(), Language.CZECH, Language.ENGLISH));
    } catch (GoogleAPIException e) {
        e.printStackTrace();
    }
}

Received error:

com.google.api.GoogleAPIException: java.lang.Exception: [google-api-translate-java] Error retrieving translation.
like image 328
AdaMoOo Avatar asked Mar 01 '13 12:03

AdaMoOo


1 Answers

This problem only appears on android when using this api client. I believe this is because this api client is old and/or poorly written.

You can attempt to get the source code from here and fix the problem yourself, or just use the api directly from Java using GET with HttpURLConnection and them parse the JSON.

like image 184
Twinsen Avatar answered Sep 27 '22 17:09

Twinsen