2011-12-14 3 views
2

Мне действительно нужен пример того, как перевести текст с помощью google translate API v2.j2me google translate api

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

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 из jmeme мидлета.

ответ

1

Быстрый взгляд показывает вам доступ к HTTPS URL:

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

использованием HttpConnection

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

Изменить что HttpsConnection

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

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

+0

Привет, Opeyemi, Спасибо за предложение, но это не помогло. – okarpov

Смежные вопросы