Forum Moderators: coopster

Message Too Old, No Replies

Youtube API with CURL/REST

Trying to use the Youtube API to create playlists

         

SupaMario123

5:39 am on Nov 23, 2009 (gmt 0)

10+ Year Member



What I've got is a script that should create a new youtube playlist. This is the code that I am using:


<?php
// The XML we are wanting to send
$xml = '
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:yt="http://gdata.youtube.com/schemas/2007">
<title type="text">Sports Highlights Playlist</title>
<summary>A selection of sports highlights</summary>
</entry>
';
$curlheader = array();
$curlheader[] = "POST /feeds/api/users/default/playlists HTTP/1.1\r\n";
$curlheader[] = "Host: gdata.youtube.com\r\n";
$curlheader[] = "Content-Type: application/atom+xml\r\n";
$curlheader[] = "Content-length: ". strlen($xml). "\r\n";
$curlheader[] = "Authorization: AuthSub \"". $key. "\"\r\n";
$curlheader[] = "GData-Version: 2\r\n";
$curlheader[] = "X-GData-Key: key=". $anotherKey. "\r\n";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://gdata.youtube.com/feeds/api/users/default/playlists');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
curl_setopt($curl, CURLOPT_HTTPHEADER, $curlheader);
$output = curl_exec($curl);
curl_close($curl);
echo $output;
?>

I keep getting the error POST requests require a Content-length header, despite it being in there. Is there something I'm missing with my code, because if there is, I certainly can't see it.

coopster

2:45 pm on Dec 5, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, SupaMario123.

Not entirely certain but you may consider trimming the whitespace from your xml variable string and urlencoding it. Let us know if you figured out what it was ...