Когнитивные услуги — Ошибка создания FaceList и PersonGroup AZURE

Не могли бы вы помочь мне, я изучаю когнитивные сервисы с помощью сервиса Azure, но у меня возникают некоторые ошибки при использовании модели форнечидо в документации

                <?php
// This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
require_once 'HTTP/Request2.php';
// Replace <Subscription Key> with a valid subscription key.
$ocpApimSubscriptionKey = '98471c5c832e466688890f6c86f6c88d';


$request = new Http_Request2('https://brazilsouth.api.cognitive.microsoft.com/face/v1.0/facelists/{faceListId}');
$url = $request->getUrl();

$headers = array(
// Request headers
'Content-Type' => 'application/json',
'Ocp-Apim-Subscription-Key' => $ocpApimSubscriptionKey ,
);

$request->setHeader($headers);

$parameters = array(
// Request parameters
'faceListId' => 'sahara'
);

$url->setQueryVariables($parameters);

$request->setMethod(HTTP_Request2::METHOD_PUT);

// Request body
$request->setBody("{body}");

try
{
$response = $request->send();
echo $response->getBody();
}
catch (HttpException $ex)
{
echo $ex;
}

?>

Я запускаю этот скрипт в php, и он дает мне следующую ошибку

{«error»: {«code»: «BadArgument», «message»: «Тело запроса недействительно.»}}

подскажите, пожалуйста, что я делаю не так, пожалуйста

1

Решение

Согласно FaceList — Создать API, формат тела

{
"name": "sample_list",
"userData": "User-provided data attached to the face list."}

Нам нужно отправить тело следующим образом, тогда оно должно работать.

// Request body
$request->setBody('{"name":"facelistName","userData":"it is optional"}'); //replace it with your name and userData

Если хотите ссылку 'HTTP/Request2.php';нам нужно установить http_request2

pear install http_request2

Как установить менеджер пакетов PEAR, пожалуйста, обратитесь к этому ссылка на сайт.

Демо-код:

<?php
// This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
require_once 'HTTP/Request2.php';

$request = new Http_Request2('https://xxx.api.cognitive.microsoft.com/face/v1.0/facelists/{faceListId}');
$url = $request->getUrl();

$headers = array(
// Request headers
'Content-Type' => 'application/json',
'Ocp-Apim-Subscription-Key' => 'xxxxxxxxxx', //replace it with your key
);

$request->setHeader($headers);

$parameters = array(
'faceListId' => 'facelistId'
);

$url->setQueryVariables($parameters);

$request->setMethod(HTTP_Request2::METHOD_PUT);

// Request body
$request->setBody('{"name":"facelistName","userData":"it is optional"}');//replace it with your name and userData

try
{
$response = $request->send();
echo $response->getBody();
}
catch (HttpException $ex)
{
echo $ex;
}

?>
1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector