【问题标题】:Google Translation API keep return error via cURLGoogle Translation API 通过 cURL 保持返回错误
【发布时间】:2016-11-09 17:03:34
【问题描述】:

我正在尝试使用 GET 到 Google 翻译 API 来翻译一个简单的字符串 "I love you"

https://www.googleapis.com/language/translate/v2?q=I+love+you&target=es&key=***************

在浏览器中我得到:

{
    "data": {
        "translations": [
            {
                "translatedText": "te amo",
                "detectedSourceLanguage": "en"
            }
        ]
    }
}

但是当我尝试使用 curl 时

curl https://www.googleapis.com/language/translate/v2?q=I+love+you&target=es&key=***************

我明白了

[3] 53561
[4] 53562
[1]   Exit 127                https://www.googleapis.com/language/translate/v2?q=I+love+you
[2]   Done                    target=es


{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Required parameter: target",
    "locationType": "parameter",
    "location": "target"
   }
  ],
  "code": 400,
  "message": "Required parameter: target"
 }
}

这是我现在在引荐来源中设置的内容


为什么我会得到不同的结果?

我需要调整我的推荐人吗?

我需要再等几分钟吗?

【问题讨论】:

    标签: curl get google-translate google-developers-console


    【解决方案1】:

    我刚刚了解到,对于 curl,您需要将带有参数的 URL 用引号括起来。

    curl "https://www.googleapis.com/language/translate/v2?q=I+love+you&target=es&key=***************"
    

    我现在得到了我的数据

    array:1 [▼
      "data" => array:1 [▼
        "translations" => array:1 [▼
          0 => array:2 [▼
            "translatedText" => "te amo"
            "detectedSourceLanguage" => "en"
          ]
        ]
      ]
    ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-25
      • 2019-01-01
      • 2021-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多