Я использую код PHP для вызова API Google Dialogflow V2. Как я могу напечатать полный результат запроса JSON?
Я пытаюсь повторить ответ, но получаю:
Исправимая фатальная ошибка: объект класса Google \ Cloud \ Dialogflow \ V2 \ DetectIntentResponse не может быть преобразован в строку в
Я надеюсь, что кто-нибудь может мне помочь! :)
<?php
namespace Google\Cloud\Samples\Dialogflow;
use Google\Cloud\Dialogflow\V2\SessionsClient;
use Google\Cloud\Dialogflow\V2\TextInput;
use Google\Cloud\Dialogflow\V2\QueryInput;
require __DIR__.'/vendor/autoload.php';
function detect_intent_texts($projectId, $text, $sessionId, $languageCode = 'nl')
{
// new session
$test = array('credentials' => 'client-secret.json');
$sessionsClient = new SessionsClient($test);
$session = $sessionsClient->sessionName($projectId, $sessionId ?: uniqid());
printf('Session path: %s' . PHP_EOL, $session);
// create text input
$textInput = new TextInput();
$textInput->setText($text);
$textInput->setLanguageCode($languageCode);
// create query input
$queryInput = new QueryInput();
$queryInput->setText($textInput);
// get response and relevant info
$response = $sessionsClient->detectIntent($session, $queryInput);
$queryResult = $response->getQueryResult();
$queryText = $queryResult->getQueryText();
$intent = $queryResult->getIntent();
$displayName = $intent->getDisplayName();
$confidence = $queryResult->getIntentDetectionConfidence();
$fulfilmentText = $queryResult->getFulfillmentText();
// output relevant info
print(str_repeat("=", 20) . PHP_EOL);
printf('Query text: %s' . PHP_EOL, $queryText);
printf('Detected intent: %s (confidence: %f)' . PHP_EOL, $displayName,
$confidence);
print(PHP_EOL);
printf('Fulfilment text: %s' . PHP_EOL, $fulfilmentText);
printf($response);
$sessionsClient->close();
}
detect_intent_texts('livebot-coftjp','hallo','123456');
?>