Curl php youtube

Hi i am trying to create php youtube api without Zend function

this is what I have so far:

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 am getting:

Exit 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.

      

Exit 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 tutorial .

I have been trying to solve this for 5 days and I have asked a couple of irc channels and forums. A friend linked me here to ask, I hope someone can help me :))

+2


source to share


2 answers


I don't have a developer key so I can't help you directly, but obviously Google has a problem with your HTTP header, so you need to figure out what you are sending in the header and not in the body of the message.The best way to do this is to check package on the wire when it leaves your car.

So install Wireshark , run it on your WAMP server, start collecting packets, run your test and then look at the http connection in the packet. Make sure what you expect.



Or maybe there is a curl way to write the package to a file instead of the server for debugging purposes. I dont know.

And this is a long shot (and would rely on them from the spec), but I noticed that you and the other person you are associated with have "Content-length". Try "Content-Length" according to the example.

+1


source


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

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



Maybe try it?

0


source







All Articles