PHP 对话流(无法构建 ApplicationDefaultCredentials)
(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);
}
我已经按照文档做了https://github.com/googleapis/google-cloud-php-dialogflow。我收到此错误 - 无法构造 ApplicationDefaultCredentials
putenv("GOOGLE_APPLICATION_CREDENTIALS=$path");
$path -> google 服务帐户 json 文件的路径。
把这段代码放在上面。
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);
}
我已经按照文档做了https://github.com/googleapis/google-cloud-php-dialogflow。我收到此错误 - 无法构造 ApplicationDefaultCredentials
putenv("GOOGLE_APPLICATION_CREDENTIALS=$path");
$path -> google 服务帐户 json 文件的路径。 把这段代码放在上面。