I'm trying to upload a movie to the Wistia API by CURL (http://wistia.com/doc/upload-api).
It works fine using the following command line, but when I put it in PHP code, I just get a blank screen with no response:
$ curl -i -d "api_password=<YOUR_API_PASSWORD>&url=<REMOTE_FILE_PATH>" https://upload.wistia.com/
PHP Code:
<?php
$data = array(
'api_password' => '<password>',
'url' => 'http://www.mysayara.com/IMG_2183.MOV'
);
$chss = curl_init('https://upload.wistia.com');
curl_setopt_array($chss, array(
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_POSTFIELDS => json_encode($data)
));
// Send the request
$KReresponse = curl_exec($chss);
// Decode the response
$KReresponseData = json_decode($KReresponse, TRUE);
echo("Response:");
print_r($KReresponseData);
?>
Thanks.
Your problem (and the difference between the command line and PHP implementation) is probably that you're JSON encoding the data in PHP, you should use http_build_query()
instead:
CURLOPT_POSTFIELDS => http_build_query($data)
For clarity, the Wistia API says it returns JSON, but doesn't expect it in the request.