【问题标题】:Google translate api 403 forbidden in java谷歌翻译api 403在java中被禁止
【发布时间】:2016-09-10 11:50:26
【问题描述】:

我使用谷歌翻译的 API 来使用文本到语音,但是当我运行此代码并将我的密钥 api 放入密钥时: 私有静态最终字符串 BASE_URL="https://www.googleapis.com/language/translate/v2?key=[key]&q=hello%20world&source=en&target=de";

public static void main(String[] args) {
    say("Hallo Welt");

}
public static void say(String text) {
    try {
        File f = new File("translate_tts.mp3");
        String sentence = URLEncoder.encode(text,"UTF-8");
        String urlString = MessageFormat.format(BASE_URL, sentence,"en");
        BinaryResource res = new Resty().bytes(new URI(urlString));
        res.save(f);

        FileInputStream in = new FileInputStream(f);
        Audio audio = Audio.getInstance();
        audio.play(in);

        Player p = new Player(in);

        p.play();

        p.close();
        f.delete();

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    } catch (JavaLayerException e) {
        e.printStackTrace();
    }

}

我有错误 403 并且服务器返回的 HTTP 响应代码错误。你能帮我解决它吗

【问题讨论】:

    标签: java google-api google-translate


    【解决方案1】:

    Google 多年前关闭了其翻译网络服务。目前只能通过网页访问。

    【讨论】:

    • google api 中我可以使用文本转语音的 api 名称是什么?我知道谷歌翻译 api 包含文本到语音(详细信息,我使用这个 api 来检测和说出越南文本。
    猜你喜欢
    • 2015-11-10
    • 2015-04-04
    • 2017-05-25
    • 2013-01-29
    • 2015-01-23
    • 2011-12-26
    • 2012-08-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多