Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

testing google translate API via curl

I am testing Google Translate API via curl and it keeps asking for parameter q while it is already there in the URL (q=Hello%20World). Why is Google Translate API returning this error?

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

Help?

like image 311
Scott Genzer Avatar asked Sep 08 '25 11:09

Scott Genzer


1 Answers

You have to surround your whole URL in double quotes, as in:

curl "https://www.googleapis.com/language/translate/v2?key=&source=en&target=de&q=Hello%20World"

Otherwise, your shell will interpret those & characters before actually executing curl; that's why you're seeing all these lines at the beginning:

[1] 16848
[2] 16849
[3] 16850
[2]-  Done                    source=en
[3]+  Done                    target=de
like image 92
asamarin Avatar answered Sep 11 '25 14:09

asamarin