I am new to Google Could platform.
I tried the translation API tutorial. For some reason, I want to use an API key to authenticate it. but the API does not accept the key in the JSON request, although it accepts the same key in the HTTP request parameter.
Is this a limitation of the Google Translation API? or do i have any error?
Below I tried:
Works when an API key is passed as a request parameter
$ curl -H 'Content-Type: application/json' 'https://translation.googleapis.com/language/translate/v2?key=xxxxxxxxxx' --data-binary @test.json
with my test.json:
{
"q": "The quick brown fox jumped over the lazy dog.",
"source": "en",
"target": "es",
"format": "text"
}
result:
{
"data": {
"translations": [
{
"translatedText": "El rpido zorro marrn salt sobre el perro perezoso."
}
]
}
}
But for some security reason, I don't want to pass this API key along the query string.
Why I do not want to use the query string
A URI with a sensitive parameter is unsafe because it is often registered or displayed in some situation, while an HTTP Header or HTTP body is not.
, ( ) , API- , .
, Api- JSON
"" JSON, . .
curl -H 'Content-Type: application/json' 'https://translation.googleapis.com/language/translate/v2' --data-binary @test.json
test.json:
{
"key": "xxxxxxxxxx",
"q": "The quick brown fox jumped over the lazy dog.",
"source": "en",
"target": "es",
"format": "text"
}
:
{
"error": {
"code": 403,
"message": "The request is missing a valid API key.",
"errors": [
{
"message": "The request is missing a valid API key.",
"domain": "global",
"reason": "forbidden"
}
],
"status": "PERMISSION_DENIED"
}
}