Tuesday, December 27, 2011

[YouTube-API] Re: 411. That’s an error. POST requests require a Content-length header. That’s all we know. CURL and PHP

Hello,

My suggestion is that you use the PHP client library for uploading
videos, and not worry about getting all the HTTP header and MIME body
values correct to begin with. You're doing something wrong with your
current approach, but I can't tell you exactly what.

http://code.google.com/apis/youtube/2.0/developers_guide_php.html

Cheers,
-Jeff Posnick, YouTube API Team
groups.google.com/group/youtube-api-gdata | apiblog.youtube.com |
@YouTubeDev


On Dec 26, 11:07 am, Panas <miguel.abadia.ar...@gmail.com> wrote:
> Hello.
>
> I want upload a video to my youtube account from my server. the video
> is a *.mp4
>
> I need use php and curl. The login its correct. I take a token. but
> google returnme a problem whith the size of header. i set the size
> like this:
>  $headers[] = "Content-Length: ".strlen($mime);
>
> where $mime its the http post body, included the file binary (whithout
> this and $headers[] = "Slug: @".$file; only the problem its the same)
>
> this is the code
>
>                                 $ch = curl_init();
>                                 curl_setopt($ch, CURLOPT_URL, "http://uploads.gdata.youtube.com/
> feeds/api/users/default/uploads");
>                                 $youtube_video_title       = "Title test";
>                                 $youtube_video_description = "Test description";
>                                 $youtube_video_category    = "cathegory test";
>                                  $youtube_video_keywords    = "prueba test keywords";
>
>                                 $xml="<?xml version='1.0'?>
>                                                 <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'>'.$youtube_video_title.'</
> media:title>
>                                                                 <media:description type='plain'>'.
> $youtube_video_description.'</media:description>
>                                                                  <media:category scheme='http://gdata.youtube.com/schemas/2007/
> categories.cat'>'.$youtube_video_category.'</media:category>
>                                                                  <media:keywords>'.$youtube_video_keywords.'</
> media:keywords>
>                                                                 </media:group>
>                                                 </entry>";
>
>                                                    $mime = "--END_OF_PART\n";
>                                                     $mime .= "Content-Type: application/atom+xml;
> charset=UTF-8";
>
>                                                     $mime.=$xml."\n--END_OF_PART\n";
>
>                                                     $mime.= "Content-Type: video/mp4 \n\n Content-Transfer-
> Encoding: binary \n\n";
>                                                     $handle = fopen($file, "r");
>                                                     $contents = fread($handle, filesize($file));
>                                                     fclose($handle);
>                                                     $mime .= $contents."\n--END_OF_PART--\n";
>
>                                                    $key = "AI39si5XuVIT4qn1EYsdr3455dGX-
> fm2it1luRU9xhPea28BD2ehxd6Bb-
> we3xkaXcpuRIn1fz8d1412AyRcOwdfewJh3jfJt0A";
>
>                                                     $headers = array();
>                                                     $headers[] = "Host: uploads.gdata.youtube.com";
>                                                     $headers[] = "Authorization: GoogleLogin token=".
> $tokenyoutube;
>                                                     $headers[] = "GData-Version: 2.0";
>                                                     $headers[] = "Content-Length: ".strlen($mime);
>                                                     $headers[] = "X-GData-Key: key=".$key;
>                                                     $headers[] = "Slug: @".$file;
>                                                     $headers[] = "Content-Type: multipart/related;
> boundary=END_OF_PART";
>                                                     $headers[] = "Connection: close";
>
>                                                                 curl_setopt($ch, CURLOPT_USERAGENT,
> $_SERVER["HTTP_USER_AGENT"]);
>                                                                 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
>                                                                 curl_setopt($ch, CURLOPT_POSTFIELDS, $mime);
>                                                                 curl_setopt($ch, CURLOPT_TIMEOUT, 30);
>                                                                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
>                                                                 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
>                                                                 $resultado = curl_exec ($ch);
>                                                                 curl_close($ch);
>
> somebody can help me?
>
> thanks

--
You received this message because you are subscribed to the Google Groups "YouTube APIs Developer Forum" group.
To post to this group, send email to youtube-api-gdata@googlegroups.com.
To unsubscribe from this group, send email to youtube-api-gdata+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/youtube-api-gdata?hl=en.

No comments:

Post a Comment