Я пытаюсь получить ответ от моего агента DialogFlow (v2!) Через PHP curl ... Поэтому я скопировал обычную команду curl из DialogFlow:
curl -H "Content-Type: application/json; charset=utf-8" -H "Authorization: Bearer ya29.xxxxhWdzg3rA" -d "{\"queryInput\":{\"text\":{\"text\":\"Gib mir Informationen über meine Dienstreise von Hamburg\",\"languageCode\":\"de\"}},\"queryParams\":{\"timeZone\":\"Europe/Berlin\"}}" "https://dialogflow.googleapis.com/v2/projects/xxxx/agent/sessions/edd016e1-9xxxxxf3787f:detectIntent"
и «преобразовал» ее в PHP:
$query = "Gib mir Informationen über meine Dienstreise nach Hamburg";
$postData = array(
'queryInput' => array(
'text' => array(
'text' => $query,
'languageCode' => 'de'
)),
'queryParams' => array(
'timeZone' => 'Europe/Berlin'
)
);
$jsonData = json_encode($postData);
$ch = curl_init('https://dialogflow.googleapis.com/v2/projects/xxxx/agent/sessions/edd016e1xxxxx7f:detectIntent');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8', 'Authorization: Bearer 6cXXXXfe'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
echo $result;
curl_close($ch);
«6cXXXXfe» - мой «токен доступа клиента» из DialogFlow.URL в curl_init () взят из предыдущей команды curl - я уверен, что ошибка есть, но я просто не могу понять, какой URL должен быть там ...
В результате я получаю ошибку:
{
"error":
{
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED"
}
}
Надеюсь, кто-нибудь может мне помочь с этим.Спасибо!