Thursday, July 12, 2012

[YouTube-API] YouTube API PHP issue: add video to playlist at a given position

Hey there,

I was trying to add a video to an existing playlist with the PHP Zend Gdata API. The example at the PHP API documentation was quite helpful, and even if it works, I think it is not quite right.

The documentation says, that in order to add a video to a playlist you have to
$entry = $this->youTube->newPlaylistListEntry($newEntry->getDOM());
but I think it is more like
$entry = $this->youTube->newPlaylistVideoEntry($newEntry->getDOM());

As soon as I used the second function, I could do
$entry->setPosition($this->youTube->newPosition(1));
in order to set the position of the Video in the playlist, while adding it. If I used newPlaylistListEntry(), this would fail, because the Zend_Gdata_YouTube_PlaylistListEntry object does not have a method named setPosition().

I think the example is incorrect here, because according to the documentation a Zend_Gdata_PlaylistListEntry is for an entry of a playlist in a list of playlists.

Additionally, it would have helped me a lot if the documentation for the constructor of Zend_Gdata_PlaylistListEntry would have said something along the line of:
DOMElement $element: (optional) DOMElement of the Zend_Gdata_YouTube_VideoEntry from which this playlist entry should be constructed.
instead of:
DOMElement
$element: (optional) DOMElement from which this object should be constructed.

I mean, it is quite obvious to me now, that by passing the DOM of the video entry to the constructor of a class that is derived thereof, I basically construct an object with the same properties wrapped in a new class. But it is not that obvious at first.

On another note: It might be great and convenient to construct objects by magic "__call" methods, but it makes it difficult to understand the code if you are looking for the the method newPlaylistListEntry() and cannot find it explicitly in the code or the code's documentation. You cannot be sure if there is a difference between
$entry = $this->youtube->newPlaylistVideoEntry(...);
and
$entry = new Zend_Gdata_PlaylistVideoEntry(...);
without finding the __call() method in the inheritance hierarchy (found it at Gdata/App.php) and studying it.

I know now there is, and that it is probably best to construct it through the newXXXX() methods, but it would have sped up my understanding if there was any information to that on the "YouTube Developer's Guide: PHP". Maybe an extra section for "$yt->registerPackage(...);", the "$yt->newXXXX()" and the magic "__call"?

Thanks and bye, Christian

--
You received this message because you are subscribed to the Google Groups "YouTube APIs Developer Forum" group.
To view this discussion on the web visit https://groups.google.com/d/msg/youtube-api-gdata/-/C0uLLP5Wv3QJ.
To post to this group, send email to youtube-api-gdata@googlegroups.com.
To unsubscribe from this group, send email to youtube-api-gdata+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/youtube-api-gdata?hl=en.

No comments:

Post a Comment