Google Vision for PDF

I realize how frustrating it could be when documentation is somewhat lacking organization, content or good examples. Here's what I ended-up doing myself, that finally allowed my script to work. Hope it'll help someone too:

require '../vendor/autoload.php';

use Google\Cloud\Storage\StorageClient;
use Google\Cloud\Vision\V1\AnnotateFileResponse;
use Google\Cloud\Vision\V1\AsyncAnnotateFileRequest;
use Google\Cloud\Vision\V1\Feature;
use Google\Cloud\Vision\V1\Feature\Type;
use Google\Cloud\Vision\V1\GcsDestination;
use Google\Cloud\Vision\V1\GcsSource;
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
use Google\Cloud\Vision\V1\InputConfig;
use Google\Cloud\Vision\V1\OutputConfig;

putenv('GOOGLE_APPLICATION_CREDENTIALS=/my-keyfile.json');

$path = 'gs://my-bucket/'.$_SESSION['pdf_file_name'];

The error indicates authentication issues. To resolve the issue, see and follow Using a service account for instructions on authenticating with a service account.

"The account used for authentication must have access to the Cloud Storage bucket that you specify for the output (roles/editor or roles/storage.objectCreator or above)." - more information here