2

Google翻訳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エミュレーターで例外をスローします

本当に助けが必要です。

私が何か間違ったことをした場合、j2me midlet から Google 翻訳 API を呼び出す方法の例を得ることができれば幸いです。

4

1 に答える 1

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);

それがどうなるか見てみましょう。

于 2012-03-23T04:10:07.963 に答える