【问题标题】:testing google translate API via curl通过 curl 测试谷歌翻译 API
【发布时间】:2016-08-09 04:16:30
【问题描述】:

我正在通过 curl 测试 Google Translate API,它一直在询问参数 q,而它已经在 URL 中(q=Hello%20World)。为什么 Google Translate API 返回此错误?

curl 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"
 }
}

帮助?

【问题讨论】:

    标签: google-translate


    【解决方案1】:

    您必须用双引号将整个 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
    

    【讨论】:

      猜你喜欢
      • 2022-01-17
      • 2016-05-02
      • 2011-12-26
      • 2010-10-10
      • 1970-01-01
      • 2012-03-13
      • 1970-01-01
      相关资源
      最近更新 更多