Reputation: 51
I'm using google php api to manage translate.
I follow the steps in google: https://cloud.google.com/translate/docs/reference/libraries#client-libraries-install-php
I think that works because i put this in my php command line:
$translate = new Google\Cloud\Translate\TranslateClient(['projectId' => 'projectid-183521' ]);
$result = $translate->translate('Hola mundo', [
'target' => 'en',
'source' => 'es',
'format' => 'text'
]);
Result:
[
"source" => "es",
"input" => "Hola mundo",
"text" => "Hello World",
"model" => null,
]
But when I run in my php project (laravel):
production.ERROR: Google\Cloud\Core\Exception\ServiceException: {
"error": {
"code": 403,
"message": "The request is missing a valid API key.",
"errors": [
{
"message": ".",
"domain": "global",
"reason": "forbidden"
}
],
"status": "PERMISSION_DENIED"
}
}
I'm using: php7.1, apache2.4, ubuntu 16.04 on AWS with load balancer.
Any idea how to solve this will be great! Thanks!
Upvotes: 0
Views: 375
Reputation: 51
As @JL-HN said the problem was about environment variable GOOGLE_APPLICATION_CREDENTIALS, for security reason apache don't read ubuntu environment variables, so I declare the environment variable in Apache *.conf file:
SetEnv GOOGLE_APPLICATION_CREDENTIALS /home/mycredentials.json
And works!
Upvotes: 4