title: What is wrong with the Youtube API (Invalid Request)?
body: <p>When I try to upload the video using the youtube API, I get error "Invalid Request".</p>
  
  <p>BUT!</p>
  
  <p>When I upload any "image" instead of "video" it returns to me the status "200" and the video ID.</p>
  
  <p>Why do I can't upload videos?</p>
  
  <pre><code>$eq = 'accountType=HOSTED_OR_GOOGLE&amp;Email='.$YOUTUBE_EMAIL.'&amp;Passwd='.$YOUTUBE_PASS.'&amp;service=youtube&amp;source='.$API_NAME;
  if ($fp = fsockopen ("ssl://www.google.com", 443, $errno, $errstr, 20))
  {
      $request ="POST /youtube/accounts/ClientLogin HTTP/1.0\r\n";
      $request.="Host: www.google.com\r\n";
      $request.="Content-Type:application/x-www-form-urlencoded\r\n";
      $request.="Content-Length: ".strlen($eq)."\r\n";
      $request.="\r\n\r\n";
      $request.=$eq;
      fwrite($fp,$request,strlen($request));
  
      while (!feof($fp))
      $response.=fread($fp,8192);
      //fclose($fp);
  }
  
  preg_match("!(.*?)Auth=(.*?)\n!si",$response,$ok);
  $AUTH_TOKEN = $ok[2];
  
  $data = "&lt;?xml version='1.0'?&gt;
  &lt;entry xmlns='http://www.w3.org/2005/Atom'xmlns:media='http://search.yahoo.com/mrss/' xmlns:yt='http://gdata.youtube.com/schemas/2007'&gt;
      &lt;media:group&gt;
       &lt;media:title type='plain'&gt;test&lt;/media:title&gt;
       &lt;media:description type='plain'&gt;test&lt;/media:description&gt;
       &lt;media:category scheme='http://gdata.youtube.com/schema /2007/categories.cat'&gt;People&lt;/media:category&gt;
       &lt;media:keywords&gt;toast, wedding&lt;/media:keywords&gt;
      &lt;/media:group&gt;
  &lt;/entry&gt; ";
  
  if ($fp = fsockopen ("gdata.youtube.com", 80, $errno, $errstr, 20))
  {
      $request ="POST /action/GetUploadToken HTTP/1.1\r\n";
      $request.="Host: gdata.youtube.com\r\n";
      $request.="Content-Type: application/atom+xml; charset=UTF-8\r\n";
      $request.="Content-Length: ".strlen($data)."\r\n";
      $request .="Authorization: GoogleLogin auth=".$AUTH_TOKEN."\r\n";
      $request.="X-GData-Client: ".$API_NAME." \r\n";
      $request.="X-GData-Key: key=".$API_KEY." \r\n";
      $request.="\r\n";
      $request.=$data."\r\n";
  
      socket_set_timeout($fp, 10);
      fputs($fp,$request,strlen($request));
      $response = fread($fp,3280);
      fclose($fp);
  }
  
  
  preg_match('|&lt;url&gt;(.*)&lt;/url&gt;|Uis', $response, $url);
  preg_match('|&lt;token&gt;(.*)&lt;/token&gt;|Uis', $response, $token);
  
  print "
      &lt;form action='".$url[1]."?nexturl=http%3A%2F%2Fwww.google.com' method='post' enctype='multipart/form-data'&gt;
        &lt;input type='file' name='file'&gt;
        &lt;input type='hidden' name='token' value='".$token[1]."'&gt;
        &lt;input type='submit' value='go'&gt;
      &lt;/form&gt; ";
  </code></pre>