tags:

views:

553

answers:

6

Hi I am trying to build php youtube api without a Zend function

this is what I have till now:

function upload() {
    $files = $_FILES;
    $name = $files['file']['name'];
    $type = $files['file']['type'];
    $size = $files['file']['size'];
    $tmp_nm = $files['file']['tmp_name'];

    $data = array('name' => 'Foo', 'file' => '@'.$tmp_nm);

    print_r($_POST);
    print_r($_FILES);

    echo 'Size '.$size;

    $headers = array( 
     "Authorization: AuthSub token=".$this->auth,
     "GData-Version: 2",
     "X-GData-Key: key=".$this->dev_key,
     "Content-length: ".$size, 
     "API_XML_request"
    );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://gdata.youtube.com/action/GetUploadToken');
    curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    curl_setopt($ch, CURLOPT_POST,1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_REFERER,true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
    curl_setopt($ch, CURLOPT_HEADER,0);

    if($this->get_info)
    {
     $this->curlget_info($ch);
        }
    $output = curl_exec($ch);

    print_r($output);

    return $output;
}

The errors I get:

Output 1

Array ( [token] => TOKEN ) Array ( [file] => Array ( [name] => 0016.png [type] => image/png [tmp_name] => D:\wamp\tmp\php178D.tmp [error] => 0 [size] => 4216 ) ) Size 4216
Google       
Error

Length Required

POST requests require a Content-length header.

Output 2

Array ( [token] => TOKEN ) Array ( [file] => Array ( [name] => Film.wmv [type] => video/x-ms-wmv [tmp_name] => D:\wamp\tmp\php11D3.tmp [error] => 0 [size] => 96589 ) ) Size 96589
Google       
Error

Length Required

POST requests require a Content-length header.

I am using this guide.

I am trying to solve this for 5 days and I asked couple irc channels and forums. A friend linked me here to ask, I hope someone will help me :))

A: 

Not sure if this is the answer, but in the example page, they put quotes around the authsub token:

Authorization: AuthSub token="DXAA...sdb8"

Maybe try that?

Geoff
Nope, I triedThe same stupid error Content length :(
Hmmm Bump !? :(
A: 

Still waiting for an answer :(

peter
A: 

this is Hopeless -_-'

peter
A: 

Have you seen this?

sv88erik
+1  A: 

I don't have a developer key so I can't help you out directly, but clearly Google has a problem with your http header so you have to find out what you're sending in the header, not the message body. The best way to do this is to inspect the packet on the wire as it leaves your machine.

So install Wireshark, start it up on your WAMP server, start capturing packets, do your test, and then look at the http connection in the packet. Make sure it's what you expect.

Or maybe there's a way for curl to write the packet to a file instead of the server for debugging purposes. I don't know.

Also it's a long shot (and would rely on them being out of spec), but I noticed that you and that other person you linked to have "Content-length". Try "Content-Length" to match the example.

indiv
A: 

oky, I scannd with wireshark and the output I had was this

POST /action/GetUploadToken HTTP/1.0\r\n [quote]Request Method: POST Request URI: /action/GetUploadToken Request Version: HTTP/1.0 Host: gdata.youtube.com\r\n Authorization: AuthSub token="D[..Verry long key..]wg\n [/quote]

one of the very interesting things are I can't see all my sended data. After the Authirization line the script stopes to send all data correctly. however, When I watch the data I send in bits/bytes mode I can see the data that should send correctly :S

So I gave my content-length an other position, and guess what..

POST /action/GetUploadToken HTTP/1.0\r\n [quote]Request Method: POST Request URI: /action/GetUploadToken Request Version: HTTP/1.0 Host: gdata.youtube.com\r\n Content-length: 5\r\n Authorization: AuthSub token="D[..very long key..]qg\n [/quote]

And the output gave this:

Token invalid - Invalid AuthSub token. Error 401

Sooo, I really don't know what to do now :( maybe a littlee help, plz

peter