$ ./2.google.sh >1.txt Use of uninitialized value in split at /usr/local/share/perl/5.26.1/WebService/GoogleAPI/Client/AuthStorage/ConfigJSON.pm line 82. $ #### GOOGLE_APPLICATION_CREDENTIALS=/home/bob/2.scripts/pages/trans1-d8f0040850a0.json /home/bob/2.scripts/pages -rw-rw-r-- 1 bob bob 2314 Nov 7 14:42 trans1-d8f0040850a0.json -----output----- json is /home/bob/2.scripts/pages/trans1-d8f0040850a0.json -------script------ #!/usr/bin/perl -w use 5.011; use WebService::GoogleAPI::Client; use Data::Dumper qw (Dumper); =head1 translation_example.pl =head2 PRE-REQUISITES Setup a Google Project in the Google Console and add the Translate API Library. You may need to enable billing to access Google Cloud Services. Setup an OAUTH Credential set and feed this into the CLI goauth included in WebService::GoogleAPI::Client and use the tool to authorise your user to access the project which will also create the local gapi.json config. =over 2 =item https://www.googleapis.com/auth/cloud-translation =item https://www.googleapis.com/auth/cloud-platform =item assumes gapi.json configuration in working directory with scoped project and user authorization =back =cut ## assumes gapi.json configuration in working directory with scoped project and user authorization my $json = $ENV{GOOGLE_APPLICATION_CREDENTIALS}; say "json is $json"; my $gapi_client = WebService::GoogleAPI::Client->new( gapi_json => $json, debug=>1 ); my $r = $gapi_client->api_query( api_endpoint_id => 'translate.translations.translate', options => { q=>'this is some text to translate into russian', target => 'ru', format => 'text', } ); say Dumper $r->json; say $r->json->{data}{translations}[0]{translatedText}; -------driver------ #!/bin/bash export GOOGLE_APPLICATION_CREDENTIALS="/home/bob/2.scripts/pages/trans1-d8f0040850a0.json" env |grep "GOOGLE" pwd ls -l *.json echo "-----output-----" ./2.trans_api.pl echo "-------script------" cat 2.trans_api.pl echo "-------driver------" cat 2.google.sh #### { "type": "service_account", "project_id": "trans1-221819", "private_key_id": ..., "private_key": "-----BEGIN PRIVATE KEY-----... "client_email": "jehosophat@trans1-221819.iam.gserviceaccount.com", "client_id": "115338096797549417908", "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://oauth2.googleapis.com/token", "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/jehosophat%40trans1-221819.iam.gserviceaccount.com" }