Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(Could not construct ApplicationDefaultCredentials) for PHP dialogflow

use Google\Cloud\Storage\StorageClient;
use Google\Cloud\Dialogflow\V2\EntityTypesClient;

$storage = new StorageClient([
            'keyFile' => json_decode(file_get_contents(storage_path('app/public/tunepath-bot-tkpf-811257321355.json')), true)
        ]);

        $entityTypesClient = new EntityTypesClient();
        $projectId = '[project_id]';
        $entityTypeId = '[ENTITY_TYPE_ID]';
        $formattedEntityTypeName = $entityTypesClient->entityTypeName($projectId, $entityTypeId);

        $entityType = $entityTypesClient->getEntityType($formattedEntityTypeName);
        foreach ($entityType->getEntities() as $entity) {
            print(PHP_EOL);
            printf('Entity value: %s' . PHP_EOL, $entity->getValue());
            print('Synonyms: ');
            foreach ($entity->getSynonyms() as $synonym) {
                print($synonym . "\t");
            }
            print(PHP_EOL);
        }

I have done according to documentation https://github.com/googleapis/google-cloud-php-dialogflow. I got this error - Could not construct ApplicationDefaultCredentials

like image 249
Sathesh Kumar Avatar asked May 22 '26 01:05

Sathesh Kumar


1 Answers

putenv("GOOGLE_APPLICATION_CREDENTIALS=$path");

$path -> path to google service acccount json file. put this code above.

like image 128
Sathesh Kumar Avatar answered May 23 '26 15:05

Sathesh Kumar