2011-12-14 3 views
2

Google 번역 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에뮬레이터

정말 도움이 필요합니다.

내가 잘못된 것을하면 j2me 미드 레트에서 google translate API를 호출하는 방법에 대한 예제를 얻는 것이 좋을 것입니다.

답변

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

관련 문제