Reputation: 31
I am using the test code found @ http://code.google.com/apis/youtube/2.0/developers_guide_php.html to create a playlist:
$newPlaylist = $yt->newPlaylistListEntry();
$newPlaylist->summary = $yt->newDescription()->setText($desc);
$newPlaylist->title = $yt->newTitle()->setText($title);
// post the new playlist
$postLocation = 'http://gdata.youtube.com/feeds/api/users/default/playlists';
try {
$playlist = $yt->insertEntry($newPlaylist, $postLocation);
}
catch (Zend_Gdata_App_Exception $e) {
echo $e->getMessage();
}
The playlist is created, but how can I get the id or url of the playlist that was just created?
Upvotes: 3
Views: 1196
Reputation: 318
You don't need any special hacks to make this work. You just need to explicitly set the protocol version for the $playlist variable, along with the $yt variable. As you stated, set the major protocol version for $yt earlier:
$yt->setMajorProtocolVersion(2);
Then after you initialize $playlist, set the protocol on that as well:
$playlist = $yt->insertEntry($newPlaylist, $postLocation, 'Zend_Gdata_YouTube_PlaylistListEntry');
$playlist->setMajorProtocolVersion(2);
Once you do this, you should be able to get your playlist ID no problem :)
$playlist_id = $playlist->getPlaylistID();
Upvotes: 0
Reputation: 189
This is a complete and utter hack, I had the same exact problem, so I went into the class at Zend/Gdata/YouTube/PlaylistListEntry.php on line 229 I commented out the if else statement.
/**
* Returns the Id relating to the playlist.
*
* @throws Zend_Gdata_App_VersionException
* @return Zend_Gdata_YouTube_Extension_PlaylistId The id of this playlist.
*/
public function getPlaylistId()
{
/*if (($this->getMajorProtocolVersion() == null) ||
($this->getMajorProtocolVersion() == 1)) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException('The yt:playlistId ' .
'element is not supported in versions earlier than 2.');
} else {*/
return $this->_playlistId;
//}
}
I would LOVE for someone to show us how to fix this the right way, but this made it so
function printPlaylistListEntry($playlistListEntry, $showPlaylistContents = false)
{
$this->yt->setMajorProtocolVersion(2);
echo '<br>Title: ' . $playlistListEntry->title->text . "\n";
echo '<br>Description: ' . $playlistListEntry->description->text . "\n";
echo '<br>playlistId: ' . $playlistListEntry->playlistId->text . "\n";
... (from the youtube v2 php api).
will return the playlistid.
Title: therighttitle
Description: therightdescription
playlistId: therightplaylistId
edit: I think this may be a better solution:
if ($this->getMajorProtocolVersion() < 2) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException('The yt:playlistId ' .
'element is not supported in versions earlier than 2.');
} else {
return $this->_playlistId;
}
replace the getPlaylistId() function with this, follows the logic of the preceding getDescription function, and its less hacky. Again completely open to critiques on why this is or is not a good idea from the zend people.
Upvotes: 0
Reputation: 53
I have the same problem. I have managed to get a bit further but I still can't get the playlistID. Here is what I did:
instead of:
$playlist = $yt->insertEntry($newPlaylist, $postLocation);
I used :
$playlist = $yt->insertEntry($newPlaylist, $postLocation, 'Zend_Gdata_YouTube_PlaylistListEntry');
But when I try to get the id by $playlist->getPlaylistID()
or $playlist->playlistId->text
I get the same exception which says :
The yt:playlistId element is not supported in versions earlier than 2.
even if I have set it earlier with $yt->setMajorProtocolVersion(2);
Upvotes: 2