【问题标题】:j2me google translate apij2me 谷歌翻译 api
【发布时间】:2012-01-19 23:59:04
【问题描述】:

我真的需要一个如何使用 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 以及 Emulator

上引发异常

真的需要帮助。

如果我做错了什么,最好能获得一个如何从 j2me midlet 调用谷歌翻译 API 的示例。

【问题讨论】:

    标签: api java-me google-translate midp google-translation-api


    【解决方案1】:

    快速浏览显示您正在访问 https 网址:

    String googleUrl="https://www.googleapis.com/language/translate/v2?key=";

    使用 httpConnection

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

    将其更改为 HttpsConnection

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

    让我们看看进展如何。

    【讨论】:

    • 嗨 Opeyemi,感谢您的建议,但没有帮助。
    猜你喜欢
    • 2011-12-26
    • 2010-10-10
    • 2013-02-15
    • 2012-01-26
    • 1970-01-01
    • 2016-11-18
    • 2018-08-20
    相关资源
    最近更新 更多