2

如何在Android應用程序中使用Google翻譯API和翻譯文本?我嘗試這樣做:Android應用程序中的Google翻譯API

http://code.google.com/p/google-api-translate-java/

,但它不工作。我也有一個Api Key。我的代碼是(根據官方爲例):

GoogleAPI.setHttpReferrer("http://mysite.com"); 
    GoogleAPI.setKey("My Key"); 
    String translatedText = Translate.DEFAULT.execute("Bonjour le monde", Language.FRENCH, Language.ENGLISH); 

我把這個代碼在我的主要活動,但我得到一個錯誤:"Unhandled exception type GoogleAPIException",有一個建議,以修復錯誤:"Surrond with Try/Catch"。但是,當我改變代碼:

try { 
String translatedText = Translate.DEFAULT.execute("Bonjour le monde", Language.FRENCH, Language.ENGLISH); 
    } catch (GoogleAPIException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

我的代碼可以正常運行,但我不能得到任何迴應(翻譯的文本)。我也設置了這個權限:<uses-permission android:name="android.permission.INTERNET"/>

我的錯誤在哪裏?

回答

5

我覺得問題出在谷歌本身,自去年秋天以來,他們正在關閉免費使用的翻譯API。

API documentation page它說:

Important: Google Translate API v2 is now available as a paid service only, and the number of requests your application can make per day is limited. As of December 1, 2011, Google Translate API v1 is no longer available; it was officially deprecated on May 26, 2011. These decisions were made due to the substantial economic burden caused by extensive abuse. For website translations, we encourage you to use the Google Website Translator gadget.

+1

感謝您的信息。實質性的經濟負擔,笑什麼。看起來谷歌正在緩慢而穩固地變得與那些飢餓的公司中的其他人一樣。在過去的美好時光中,谷歌所有的東西都是免費的,但現在他們正在創造數萬億美元,他們需要更多。 – Yster 2014-03-10 16:15:38