如何通过代码使用Google翻译API [英] How to use Google translate API from code
问题描述
我正在尝试创建一个将单词发送到 translate.google.com 的应用,获取翻译结果并将其显示给用户.我编写了URL,但是我不知道如何从网页中提取单词/短语.
伪示例: en是英语代码,es是西班牙语代码
String from = "en";
String to = "es";
String word = "hello"; //this will be user input text really
String URL = "http://www.translate.google.com/#" + from + "/" + to + "/" + word;
因此,请求网址应类似于 http://www.translate.google. com/#en/es/hello
我现在需要能够从结果框中检索信息并将其放置在字符串中,以便可以将其显示给用户.
Google翻译提供了用于检索翻译的API.您应该使用json对象和GET请求到Google翻译服务器. 在此链接中,您可以找到带有代码示例的官方《开发人员指南》. /p>
I am trying to create an app that send a word to translate.google.com, take the result of the translation and display it to the user. I composed the URL but I do not know how to extract the word/phrase from the webpage.
Example pseudo: en is code for english and es is code for spanish
String from = "en";
String to = "es";
String word = "hello"; //this will be user input text really
String URL = "http://www.translate.google.com/#" + from + "/" + to + "/" + word;
Therefore the request URL will look like http://www.translate.google.com/#en/es/hello
I now need to be able to retrieve the information from the result box and place it in a String so I can display it to the user.
Google translate provide API for retrieving translations. You should use json object and GET request to the google translate server. In this link you can find the official Developer's Guide with code examples.
这篇关于如何通过代码使用Google翻译API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!