j2me гугл переводчик апи

Мне очень нужен пример того, как перевести текст с помощью Google Translate API v2.

Я уже реализовал следующее:

String googleUrl="https://www.googleapis.com/language/translate/v2?key=<My Key>";
googleUrl+="&q=";
googleUrl+=urlEncode(txtFeedback.getString());
googleUrl+="&source=";
googleUrl+=System.getProperty("microedition.locale").substring(0, 2);
googleUrl+="&target=en";
HttpConnection googlAPI = null;
DataInputStream dis = null;

StringBuffer response = new StringBuffer();
googlAPI = (HttpConnection)Connector.open(googleUrl);


googlAPI.setRequestMethod(HttpConnection.GET);
dis = new DataInputStream(googlAPI.openInputStream());
int ch;
while ((ch = dis.read()) != -1) {
    response.append((char) ch);
}


String tt = response.toString();
tt = tt.substring(tt.indexOf("{"));
JSONObject js = new JSONObject(tt);
params +=js.getJSONObject("data").getJSONArray("translations").getJSONObject(0)
              .getString("translatedText") + crlf;

но этот код выдает исключение сертификата: сертификат был выдан неизвестным лицом

он выдает исключение на моем реальном устройстве Samsung GT-S5230, а также на эмуляторе

Очень нужна помощь.

Если я сделаю что-то не так, было бы здорово получить пример того, как вызывать API Google Translate из мидлета j2me.


person okarpov    schedule 14.12.2011    source источник


Ответы (1)


Быстрый просмотр показывает, что вы обращаетесь к URL-адресу https:

Строка googleUrl="https://www.googleapis.com/language/translate/v2?key=";

используя httpConnection

googlAPI = (HttpConnection) Connector.open(googleUrl);

Измените это на HttpsConnection

HttpsConnection googlAPI = null;
...
googlAPI = (HttpsConnection) Connector.open(googleUrl);

и посмотрим, как пойдет.

person kehers    schedule 23.03.2012
comment
Привет, Opeyemi, спасибо за предложение, но оно не помогло. - person okarpov; 31.05.2012