php - YouTube API - Direct Upload - 413 Request Entity Too Large -
i've been trying upload videos youtube api via direct upload. cracked oauth process , have valid token. need 2 things youtube, authenticate , upload. not browsing, or using of other functionality. users upload videos website, , send them youtube playback.
i feel i've come 80-90% of way on own here, not want scrap , use zend library google provides.
problem: when send request response:
http/1.1 413 request entity large content-type: text/html; charset=utf-8 content-length: 171 date: thu, 18 apr 2013 18:33:22 gmt expires: thu, 18 apr 2013 18:33:22 gmt cache-control: private, max-age=0 x-content-type-options: nosniff x-frame-options: sameorigin x-xss-protection: 1; mode=block server: gse connection: close if turn on warnings, broken pipe warning, code trying upload data through closed/refused connection.
my request this:
post /feeds/api/users/default/uploads http/1.1 host: gdata.youtube.com connection: close user-agent: php accept-encoding: identity authorization: bearer <token here> gdata-version: 2.0 x-gdata-key: key=<mykeyishere> slug: throwing_can.mp4 content-type: multipart/related; boundary="5170429d1b193" content-length: 3920610 with file chunked , written stream.
function ytapi_write_file($handle, $path, $chunksize = 8192){ $filehandle = fopen($path, 'r'); while(!feof($filehandle)){ fwrite($handle, fread($filehandle, $chunksize)); } fclose($filehandle); $filehandle = null; } function ytapi_write($handle, $request){ fwrite($handle, $request); return $request; } like so.
ytapi_write($handle, $start); //this writes header. ytapi_write_file($handle, $path, 8192); //this writes file raw/binary. ytapi_write($handle, $end); //this writes final boundary. also, use header info:
$_header = array( 'host'=>'gdata.youtube.com', 'connection'=>'close', 'user-agent'=>'php', 'accept-encoding'=>'identity' ); any idea i'm doing wrong? can provide more information if needed. file uploading little on 3mb, file sitting on server in question. i've verified location correct.
update
changed uploads.gdata.youtube.com
now error message:
host: uploads.gdata.youtube.com connection: close user-agent: php accept-encoding: identity tcp://uploads.gdata.youtube.com:80http/1.1 400 bad request server: http upload server built on apr 8 2013 13:06:58 (1365451618) x-gdata-user-country: content-type: application/vnd.google.gdata.error+xml x-guploader-uploadid: <some id> date: thu, 18 apr 2013 19:42:14 gmt pragma: no-cache expires: fri, 01 jan 1990 00:00:00 gmt cache-control: no-cache, no-store, must-revalidate content-length: 228 connection: close
this mine implementation:
$data = '<?xml version="1.0"?> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <entry xmlns="http://www.w3.org/2005/atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:yt="http://gdata.youtube.com/schemas/2007"> <media:group> <media:title type="plain">' . $title . '</media:title> <media:description type="plain">' . trim($description) . '</media:description> <media:keywords>' . $tags . '</media:keywords> <media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat">music</media:category> </media:group> </entry>'; $headers = array( 'authorization: googlelogin auth=' . $auth, 'gdata-version: 2', 'x-gdata-key: key=<key>', 'slug: ' . basename($videopath) ); $tmpfname = tempnam("/tmp", "youtube"); $handle = fopen($tmpfname, "w"); fwrite($handle, $data); fclose($handle); $post = array( 'xml' => '@' . $tmpfname . ";type=application/atom+xml", 'video' => '@' . $videopath . ";type=video/mp4", ); $ch = curl_init(); curl_setopt($ch, curlopt_url, "uploads.gdata.youtube.com/feeds/api/users/default/uploads"); curl_setopt($ch, curlopt_httpheader, $headers); curl_setopt($ch, curlopt_post, true); curl_setopt($ch, curlopt_postfields, $post); curl_setopt($ch, curlopt_returntransfer, true); $content = curl_exec($ch); curl_close($ch);
Comments
Post a Comment