I have the following code, modified from Google\'s documentation:
$GOOGLE_APPLICATION_CREDENTIALS = \"./[path].json\";
$_ENV[\"GOOGLE_APPLICATION
Attempt to use the ImageAnnotator like below When running the code, observe that you get an error: Could not construct ApplicationDefaultCredentials
solution
putenv("GOOGLE_APPLICATION_CREDENTIALS=/home/netwons/Downloads/AIz.json");
but not work. OS: Ubuntu PHP version: 7.2.4 Package name and version: google/cloud-vision 0.19.1 this is code
$imageAnnotator = new ImageAnnotatorClient();
// $client->setAuthConfig('key.json');
# the name of the image file to annotate
$fileName = '2.png';
# prepare the image to be annotated
$image = file_get_contents($fileName);
# performs label detection on the image file
$response = $imageAnnotator->labelDetection($image);
$labels = $response->getLabelAnnotations();
if ($labels) {
echo("Labels:" . PHP_EOL);
foreach ($labels as $label) {
echo($label->getDescription() . PHP_EOL);
}
} else {
echo('No label found' . PHP_EOL);
}