Мне нужно отправить файл PDF в Google Vision, чтобы извлечь и вернуть текст. Из документации я понял, что файл DPF должен находиться в Google Storage, поэтому я помещаю этот файл в свое хранилище Google Storage следующим образом:
require '../vendor/autoload.php';
use Google\Cloud\Storage\StorageClient;
$storage = new StorageClient([
'keyFilePath' => '/my-keyfile.json',
'projectId' => PROJECT_ID
]);
$bucket = $storage->bucket(BUCKET_NAME);
$bucket->upload(
fopen($_SESSION['local_pdf_url'], 'r')
);
Это работает. После того, как я перенаправлю на другую страницу, которая должна передать этот файл в Vision, и вот где он терпит неудачу. Я нашел пример функции . Вот код:
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;
$storage = new StorageClient([
'keyFilePath' => '/my-keyfile.json',
'projectId' => PROJECT_ID
]);
$path = 'gs://my-bucket/'.$_SESSION['pdf_file_name'];
Когда я запускаю второй скрипт, я получаю следующие ошибки:
Неустранимая ошибка: Uncaught DomainException: не удалось загрузить значение по умолчанию
полномочия. Перейти к
https://developers.google.com/accounts/docs/application-default-credentials
для получения дополнительной информации в
/home/domain/vendor/google/auth/src/ApplicationDefaultCredentials.php:168
Трассировка стека: # 0
/home/domain/vendor/google/gax/src/CredentialsWrapper.php(197):
Google \ Auth \ ApplicationDefaultCredentials :: getCredentials (массив,
Объект (Google \ Auth \ HttpHandler \ Guzzle6HttpHandler), NULL, NULL) # 1
/home/domain/vendor/google/gax/src/CredentialsWrapper.php(114):
Google \ ApiCore \ CredentialsWrapper :: buildApplicationDefaultCredentials (Array,
Объект (Google \ Auth \ HttpHandler \ Guzzle6HttpHandler)) # 2
/home/domain/vendor/google/gax/src/GapicClientTrait.php(326):
Google \ ApiCore \ CredentialsWrapper :: build (Array) # 3
/home/domain/vendor/google/gax/src/GapicClientTrait.php(308):
Google \ Cloud \ Зрение \ V1 \ Gapic \ ImageAnnotatorGapicClient-> createCredentialsWrapper (NULL,
Массив) # 4
/home/domain/vendor/google/cloud/Vision/src/V1/Gapic/ImageAnnotatorGapicClient.php(216):
Google \ Clou in
/home/domain/vendor/google/gax/src/CredentialsWrapper.php в строке 200
Как мне пройти аутентификацию для этой услуги? Чего мне не хватает?