Problems with Curl using Face++

Asked

Viewed 76 times

2

I’m using a Face++ API for visual face recognition.

I set up a code in PHP that sends a face.jpg to their API according to the rules in the documentation, but this Curl is either not sending the data or is not working, because on Linux on shell_exec it works.

When trying to transfer the code to PHP it didn’t work.

My cUEL code on Linux that works:

curl -X POST "https://api-us.faceplusplus.com/facepp/v3/detect" -F "api_key=<api_key>" \
-F "api_secret=<api_secret>" \
-F "image_file=@image_file.jpg" \
-F "return_landmark=1" \
-F "return_attributes=gender,age"

My PHP code that brings me no return:

$data = array(
    'api_key' => '<APIKEYAKI>', 
    'api_secret' => '<SECRETAKI>',
    'return_landmark' => '1',
    'return_attributes' => 'gender,age'
);   

$data['image_file'] = '@./jasar.jpg';

$handle = curl_init('https://api-us.faceplusplus.com/facepp/v3/search');
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
$dados = curl_exec($handle);
curl_close($handle);

echo $dados;

I tried to change PHP codes; I picked up several examples right here on the site and nothing.

It follows updated Cod that already returns an error but now does not make the jpg post

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api-us.faceplusplus.com/facepp/v3/search");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "api_key=123456&api_secret=32164&return_attributes=gender,age&outer_id=facesetpocface&image_file=@".realpath('jasar.jpg'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);


print($result);
  • Have you tried to put the full path to the image instead of the relative path?

  • yes guy tried to user that real_patch of php.

  • Try to direct this request with the curl for a page of yours and make sure the request is correct.

  • blank turn

  • The answer, yes. But what about the request? That’s why I told you to make the request in your URL and debug the information that arrived.

  • changed my Cod and now returns error but it is not doing the post of my jpg image I will update in the post

  • Failed to put the answer you got with this new code.

  • nothing comes atela gets blank tested on multiple servers and location.

Show 3 more comments

1 answer

2


Try it this way and tell me if it worked

$handle = curl_init('https://api-us.faceplusplus.com/facepp/v3/search');
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, array(
    'api_key' => '<APIKEYAKI>', 
    'api_secret' => '<SECRETAKI>',
    'image_file' => curl_file_create(realpath('marquito.jpg')),   
    'return_landmark' => '1',
    'return_attributes' => 'gender,age'
));
$dados = curl_exec($handle);
curl_close($handle);

echo $dados;
  • back info now but ta saying that image_file is missing.

  • I put a realpath from php and it worked thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.