Для одного из сайтов делаю модуль для работы c youtube. Мне нужно сделать возможность закачивать ролики на youtube. В документации сказано что нужно отправить вот такой запрос:
| Код | POST /feeds/api/users/default/uploads HTTP/1.1 Host: uploads.gdata.youtube.com Authorization: AuthSub token=<authentication_token> X-GData-Client: <client_id> X-GData-Key: key=<developer_key> Slug: <video_filename> Content-Type: multipart/related; boundary=<boundary_string> Content-Length: <content_length> Connection: close
--<boundary_string> Content-Type: application/atom+xml; charset=UTF-8
API_XML_request --<boundary_string> Content-Type: <video_content_type> Content-Transfer-Encoding: binary
<Binary File Data> --<boundary_string>--
|
С cURL работать начал недавно поэтому не получается никак сформировать такой запрос. Как это можно сделать?
Это пример того как я пытаюсь делать. Здесь мне выдается сообщение "Incomplete multipart body". В чем его Incomplete-ность я не могу понять.
| Код | $bnd_string = md5(uniqid(time()));
$ch = curl_init();
@curl_setopt($ch, CURLOPT_URL, 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads'); @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
$str_post = '<?xml version="1.0"?>чтоб не усложнять код весь xml не привожу';
$yt_dev_key = 'sdasdasdas'; $yt_marker = 'dsfsdfsdfsdf';
$body_2 = ''; $body_2 .= '--'.$bnd_string; $body_2 .= 'Content-Type: application/atom+xml; charset=UTF-8'; $body_2 .= $str_post; $body_2 .= '--'.$bnd_string; $body_2 .= 'Content-Type: application/octet-stream'; $body_2 .= 'Content-Transfer-Encoding: binary';
$f = fopen($_FILES['yt_file']['tmp_name'], 'rb'); while (!feof($f)) { $body_2 .= fread($f, 8192); }
fclose($f);
$body_2 .= '--'.$bnd_string.'--';
$headers = array(); $headers[] = 'POST /feeds/api/users/default/uploads HTTP/1.1'; $headers[] = 'Host: uploads.gdata.youtube.com'; $headers[] = 'Authorization: AuthSub token='.trim($yt_marker); $headers[] = 'X-GData-Key: key='.$yt_dev_key; $headers[] = 'Slug: video_name_t.flv'; $headers[] = 'Content-Type: multipart/related; boundary="'.$bnd_string.'"'; $headers[] = 'Content-Length: '.strlen($body_2, '8bit'); $headers[] = 'Connection: close';
@curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); @curl_setopt($ch, CURLOPT_POSTFIELDS, $body_2); @curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// @curl_setopt($ch, CURLOPT_POST, 1);
$res = curl_exec($ch);
|
|