PHP-google vision API-未找到类

PHP-google vision API-未找到类,php,google-vision,Php,Google Vision,我在尝试使用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 我在windows上使用xampp。我使用composer(作为管理员)安

我在尝试使用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
我在windows上使用xampp。我使用composer(作为管理员)安装了GoogleAPI

我还运行(作为管理员)

已安装google cloud sdk

这是我的密码

<?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>';

?>

根据官方文档,我建议使用以下php客户端库:

<?php
namespace Google\Cloud\Samples\Vision;

use Google\Cloud\Vision\V1\ImageAnnotatorClient;

$path = 'caption.jpg';

    $imageAnnotator = new ImageAnnotatorClient();

    # annotate the image
    $image = file_get_contents($path);
    $response = $imageAnnotator->textDetection($image);
    $texts = $response->getTextAnnotations();

    printf('%d texts found:' . PHP_EOL, count($texts));
    foreach ($texts as $text) {
        print($text->getDescription() . PHP_EOL);

        # get bounds
        $vertices = $text->getBoundingPoly()->getVertices();
        $bounds = [];
        foreach ($vertices as $vertex) {
            $bounds[] = sprintf('(%d,%d)', $vertex->getX(), $vertex->getY());
        }
        print('Bounds: ' . join(', ', $bounds) . PHP_EOL);
    }

    $imageAnnotator->close();

?>
使用来自的代码

下面是index.php

Fatal error: Uncaught Error: Class 'Google\Cloud\Vision\V1\ImageAnnotatorClient' not found in C:\xampp\htdocs\index.php:8 Stack trace: #0 {main} thrown in C:\xampp\htdocs\index.php on line 8
这是composer.json


这可能是autoload.php的路径问题尝试创建一个project文件夹,然后运行composer Required google/cloud vision。使用cmd,cd到C:\xampp\htdocs,其中包含my index.php和其他文件,然后运行命令。它确实安装了东西,但错误仍然存在,您安装了哪个版本的google/cloud vision?对于最新版本的使用#导入google cloud客户端库使用google\cloud\vision\V1\ImageAnnotatorClient;有关更多信息,请访问composer.json的此链接,该版本为“google/cloud vision”:“^1.2”给出了类似的错误:致命错误:未捕获错误:在C:\xampp\htdocs\index.php中找不到类“VisionClient”。php:7堆栈跟踪:#0{main}在C:\xampp\htdocs\index.php的第7行抛出
# imports the Google Cloud client library
use Google\Cloud\Vision\V1\ImageAnnotatorClient;

<?php
namespace Google\Cloud\Samples\Vision;

use Google\Cloud\Vision\V1\ImageAnnotatorClient;

$path = 'caption.jpg';

    $imageAnnotator = new ImageAnnotatorClient();

    # annotate the image
    $image = file_get_contents($path);
    $response = $imageAnnotator->textDetection($image);
    $texts = $response->getTextAnnotations();

    printf('%d texts found:' . PHP_EOL, count($texts));
    foreach ($texts as $text) {
        print($text->getDescription() . PHP_EOL);

        # get bounds
        $vertices = $text->getBoundingPoly()->getVertices();
        $bounds = [];
        foreach ($vertices as $vertex) {
            $bounds[] = sprintf('(%d,%d)', $vertex->getX(), $vertex->getY());
        }
        print('Bounds: ' . join(', ', $bounds) . PHP_EOL);
    }

    $imageAnnotator->close();

?>
Fatal error: Uncaught Error: Class 'Google\Cloud\Vision\V1\ImageAnnotatorClient' not found in C:\xampp\htdocs\index.php:8 Stack trace: #0 {main} thrown in C:\xampp\htdocs\index.php on line 8
{
    "require": {
        "google/cloud-vision": "^1.2"
    }
}