[英]Google translate api on android gives error 'GoogleJsonResponseException: 400 Bad Request'
When trying to access google translate api from an android application it gives the following error: 尝试从Android应用程序访问Google翻译API时,出现以下错误:
java.lang.RuntimeException: An error occurred while executing doInBackground()
....
Caused by: com.google.cloud.translate.TranslateException: Invalid Value
...
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Invalid Value",
"reason" : "invalid"
} ],
"message" : "Invalid Value"
The code inside doInBackground method() is: doInBackground method()中的代码是:
Translate translate = TranslateOptions.newBuilder()
.setApiKey("myAPI_key").build().getService();
Translation translation = translate.translate(
params[0],
Translate.TranslateOption.sourceLanguage("en"),
Translate.TranslateOption.targetLanguage("al"));
return translation.getTranslatedText(); }
The string I pass is in english. 我传递的字符串是英语。 Can anyone help me figuring out this error?
谁能帮我弄清楚这个错误? Thanks in advance.
提前致谢。
Your problem is in the line: 您的问题所在:
Translate.TranslateOption.targetLanguage("al"));
al is not a correct code for any supported language. 对于任何受支持的语言, al都不是正确的代码。
You can check the complete list of supported languages in the Google APIs Explorer . 您可以在Google APIs Explorer中查看支持的语言的完整列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.