本文整理汇总了Java中com.google.api.GoogleAPI类的典型用法代码示例。如果您正苦于以下问题:Java GoogleAPI类的具体用法?Java GoogleAPI怎么用?Java GoogleAPI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GoogleAPI类属于com.google.api包,在下文中一共展示了GoogleAPI类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: translate
import com.google.api.GoogleAPI; //导入依赖的package包/类
static String translate(String sourceLanguageCode, String targetLanguageCode, String sourceText) {
Log.d(TAG, sourceLanguageCode + " -> " + targetLanguageCode);
// Truncate excessively long strings. Limit for Google Translate is 5000 characters
if (sourceText.length() > 4500) {
sourceText = sourceText.substring(0, 4500);
}
GoogleAPI.setKey(API_KEY);
GoogleAPI.setHttpReferrer("https://github.com/rmtheis/android-ocr");
try {
return Translate.DEFAULT.execute(sourceText, Language.fromString(sourceLanguageCode),
Language.fromString(targetLanguageCode));
} catch (Exception e) {
Log.e(TAG, "Caught exeption in translation request.");
return Translator.BAD_TRANSLATION_MSG;
}
}
示例2: googleValidator
import com.google.api.GoogleAPI; //导入依赖的package包/类
/**
* 访问goolge api以验证 Key是否可用。 ;
*/
private void googleValidator() {
final String googleKey = googleKeyText.getText();
BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {
public void run() {
// TODO Auto-generated method stub
if (googleKey != null && !googleKey.trim().equals("")) {
GoogleAPI.setHttpReferrer("http://www.heartsome.net");
GoogleAPI.setKey(googleKey);
try {
String result = Translate.DEFAULT.execute("test", GoogleTransUtils.processLanguage("en-US"),
GoogleTransUtils.processLanguage("zh-CN"));
if (result.equals("测试")) {
googleState = true;
}
} catch (GoogleAPIException e) {
googleState = false;
}
} else {
googleState = false;
}
}
});
}
示例3: validator
import com.google.api.GoogleAPI; //导入依赖的package包/类
/**
* 访问api以验证 Key是否可用。 ;
*/
private void validator() {
final String googleKey = googleKeyText.getText();
BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {
public void run() {
// TODO Auto-generated method stub
if (googleKey != null && !googleKey.trim().equals("")) {
GoogleAPI.setHttpReferrer("http://www.heartsome.net");
GoogleAPI.setKey(googleKey);
try {
String result = Translate.DEFAULT.execute("test", GoogleTransUtils.processLanguage("en-US"),
GoogleTransUtils.processLanguage("zh-CN"));
if (result.equals("测试")) {
state = true;
}
} catch (GoogleAPIException e) {
state = false;
}
} else {
state = false;
}
}
});
}
示例4: translateString
import com.google.api.GoogleAPI; //导入依赖的package包/类
public String translateString( String source ) {
String translatedText = "";
GoogleAPI.setHttpReferrer("http://code.google.com/p/google-api-translate-java/");
//Translate.setHttpReferrer("http://code.google.com/p/google-api-translate-java/");
try {
translatedText = Translate.execute(source, Language.ENGLISH, Language.FRENCH);
} catch (Exception e) {
System.err.println( "Exception " + e.getMessage() );
}
return removeSpaces ( translatedText );
}
示例5: googleTranslate
import com.google.api.GoogleAPI; //导入依赖的package包/类
public void googleTranslate() {
String clientId = googleTranslatePropertyResolver.getProperty("clientId");
String clientSecret = googleTranslatePropertyResolver.getProperty("clientSecret");
log.info("googleTranslate.init: {} {}", clientId, clientSecret);
GoogleAPI.setHttpReferrer(clientId);
// Set the Google Translate API key
// See: http://code.google.com/apis/language/translate/v2/getting_started.html
GoogleAPI.setKey(clientSecret);
}
示例6: translate
import com.google.api.GoogleAPI; //导入依赖的package包/类
public static String translate(String text, Language sourceLang, Language targetLang, boolean markTranslation) {
String translatedText = null;
if(text != null && sourceLang != null && targetLang != null) {
try {
System.out.println("Google Translating '"+text+"' from '"+sourceLang+"' to '"+targetLang+"'");
GoogleAPI.setHttpReferrer("http://wandora.org");
if(apikey == null || apikey.length() == 0) {
apikey = WandoraOptionPane.showInputDialog(Wandora.getWandora(), "Give your Google Translate API key?", "", "Give your Google Translate API key?");
if(apikey != null) apikey = apikey.trim();
}
if(apikey != null) {
GoogleAPI.setKey(apikey);
translatedText = Translate.DEFAULT.execute(text, sourceLang, targetLang);
if(translatedText != null && translatedText.length() == 0) {
translatedText = null;
}
if(translatedText != null && markTranslation) {
translatedText += " [GOOGLE TRANSLATION]";
}
}
}
catch(Exception e) {
Wandora.getWandora().handleError(e);
//e.printStackTrace();
}
}
return translatedText;
}
示例7: getGoogleTranslation
import com.google.api.GoogleAPI; //导入依赖的package包/类
private String getGoogleTranslation(String text, String originLangStr, String targetLangStr) throws GoogleAPIException {
if (text.equals("") || text.equals(" ")) //avoid empty text
return "";
//String translatedText;
String translatedText=text;// + "_" + num_tranlated_characters;
//Check if text is in local dictionary
if (isInLocalDictionary(text))
return getLocalTranslation(text);
else if(Parameters.call_online_translator){
// Set Google key here
//GoogleAPI.setHttpReferrer("http://code.google.com/p/google-api-translate-java/");
//GoogleAPI.setKey("AIzaSyALd_XsjljQ0U0n8SB_3q6Iocc8kPeLsCo"); //api yuan gong
GoogleAPI.setHttpReferrer("https://code.google.com/p/logmap-matcher/");
//GoogleAPI.setKey("AIzaSyCXIH0M0Ya4WpnbHYIqNrRC4wXOqtszQuU"); //university of oxford api, max 100,000. Old key
GoogleAPI.setKey("AIzaSyCOXm6fqYcqJtpFSrlMsgAy1VPkgNcrD2k"); //New key
Language originLang = LanguageMap.get(originLangStr);
Language targetLang = LanguageMap.get(targetLangStr);
num_tranlated_characters+=text.length();
num_calls++;
LogOutput.printAlways("Translating: '" + text + "' from " + originLangStr + " to " + targetLangStr + " using Google API. Num chars translated so far: " + num_tranlated_characters);
//Google call
if (!Parameters.is_test_mode_multilingual){
try{
translatedText = Translate.DEFAULT.execute(text, originLang, targetLang);
}
catch (Exception e){
LogOutput.printError("Error Translating: '" + text + "' from " + originLangStr + " to " + targetLangStr + " using Google API. " + e.getMessage());
e.printStackTrace();
return "";
}
//System.out.println(translatedText.length());
}
else{ //This is for test only!
translatedText=text + "_" + num_tranlated_characters + "_g";
}
//System.out.println(translatedText);
//Store in on-the-fly dictionary
addTranslation2Map(text, translatedText);
}
return translatedText;
}
示例8: SimpleMatcherGoogleImpl
import com.google.api.GoogleAPI; //导入依赖的package包/类
/**
*
*/
public SimpleMatcherGoogleImpl() {
String googleKey = this.parameters.getGoolgeKey();
GoogleAPI.setHttpReferrer("http://www.heartsome.net");
GoogleAPI.setKey(googleKey);
}
示例9: SimpleMatcherGoogleImpl
import com.google.api.GoogleAPI; //导入依赖的package包/类
/**
*
*/
public SimpleMatcherGoogleImpl() {
String googleKey = this.parameters.getKey();
GoogleAPI.setHttpReferrer("http://www.heartsome.net");
GoogleAPI.setKey(googleKey);
}