简体   繁体   English

Android上的Google翻译API给出错误“ GoogleJsonResponseException:400错误的请求”

[英]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.

相关问题 com.google.api.client.googleapis.json.GoogleJsonResponseException:400错误的请求 - com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request Google Places API:错误400 :(错误请求) - Google Places API: Error 400: (Bad Request) “ Id不能为零”-GoogleJsonResponseException 400错误请求 - “Id cannot be zero” - GoogleJsonResponseException 400 Bad Request GoogleJsonResponseException:400错误的请求“无效的查询参数类型” - GoogleJsonResponseException: 400 Bad Request “Invalid query parameter type” Google 电子表格 API,400 错误错误请求:无法解析范围 - Google spreadsheet API, 400 error bad request : unable to parse range 查询Google的Directory API-错误:400错误的请求 - Querying Google’s Directory API - Error: 400 Bad Request Android Drive Api收到400错误请求 - Android Drive Api getting 400 Bad Request Android Rest Api Post 400错误请求 - Android Rest Api Post 400 bad request Google API for Google Docs,请求文档列表 - 400 Bad Request - Google API for Google Docs, requesting a list of documents — 400 Bad Request 错误400错误的请求 - Error 400 Bad Request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM