I get this error message while trying to use google vision API
Fatal error: Uncaught Error: Class 'Google\Cloud\Vision\VisionClient' not found in C:\xampp\htdocs\index.php:7 Stack trace: #0 {main} thrown in C:\xampp\htdocs\index.php on line 7
I'm using xampp on windows. I installed Google api using composer (as admin)
composer require google/cloud-vision
I also run (as admin)
composer install
composer update
google cloud sdk is installed.
this is my code
<?php
require 'C:\Users\MyUser\vendor\autoload.php';
use Google\Cloud\Vision\VisionClient;
$path = 'caption.jpg';
$vision = new VisionClient([
'projectId' => 'my-project-numbers',
'keyFilePath' => 'my-key.json'
]);
// Annotate an image, detecting faces.
$image = $vision->image(
fopen($path, 'r'),
['text']
);
$tadaa = $vision->annotate($image);
echo '<pre>';
var_dump($tadaa->text());
echo '</pre>';
?>
According to the official documentation, I would recommend to use this php client library:
Quickstart: Using client libraries Vision Api