0

I'm trying to make a GET to Google Translation API to translate a simple string "I love you"

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

In the browser I get:

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

enter image description here

But when I try it with curl

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

I got

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

Here is what I set in my referer right now

enter image description here


Why do I get a different result ?

Do I need to adjust my referer ?

Do I need to wait a couple more minutes ?

halfer
  • 19,824
  • 17
  • 99
  • 186
code-8
  • 54,650
  • 106
  • 352
  • 604

1 Answers1

0

I just learn that for curl you need to wrap URLs that have params with quotes.

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

I got my data now

array:1 [▼
  "data" => array:1 [▼
    "translations" => array:1 [▼
      0 => array:2 [▼
        "translatedText" => "te amo"
        "detectedSourceLanguage" => "en"
      ]
    ]
  ]
]
code-8
  • 54,650
  • 106
  • 352
  • 604