I solved it by declaring an environment variable in my apache conf file: SetEnv GOOGLE_APPLICATION_CREDENTIALS /home/mycredentials.json
Google Translate Api Fail in laravel project
I'm using google translate api to manage translate in my site.
I follow the steps in google: https://cloud.google.com/translate/docs/reference/libraries#client-libraries-install-php to install my service account.
I think that works because I put in php artisan tinker:
$translate = new Google\Cloud\Translate\TranslateClient(['projectId' => 'mykey-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 laravel controller throw next error: production.ERROR: Google\Cloud\Core\Exception\ServiceException: { "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" } }
Some clue!
Please or to participate in this conversation.