我正在通过curl 测试Google Translate API,它不断询问参数q,而参数q 已经存在于URL 中(q=Hello%20World)。为什么 Google Translate API 返回此错误?
卷曲https://www.googleapis.com/language/translate/v2?key= &source=en&target=de&q=Hello%20World
[1] 16848
[2] 16849
[3] 16850
[2]- Done source=en
[3]+ Done target=de
foo:~ foo$ {
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Required parameter: q",
"locationType": "parameter",
"location": "q"
},
{
"domain": "global",
"reason": "required",
"message": "Required parameter: target",
"locationType": "parameter",
"location": "target"
}
],
"code": 400,
"message": "Required parameter: q"
}
}
Run Code Online (Sandbox Code Playgroud)
帮助?
小智 6
您必须将整个 URL 用双引号引起来,如下所示:
curl "https://www.googleapis.com/language/translate/v2?key=&source=en&target=de&q=Hello%20World"
&否则,您的 shell 将在实际执行之前解释这些字符curl;这就是为什么你会在开头看到所有这些行:
[1] 16848
[2] 16849
[3] 16850
[2]- Done source=en
[3]+ Done target=de
Run Code Online (Sandbox Code Playgroud)