我想使用GData将视频添加到播放列表。所以我创建播放列表没有问题,但我无法向其中添加视频。我是这样做的:
$playlist = $yt->newPlaylistListEntry();
$playlist->summary = $yt->newDescription()->setText("test");
$playlist->title = $yt->newTitle()->setText("test2");
$postLocation = 'http://gdata.youtube.com/feeds/api/users/default/playlists';
$yt->insertEntry($playlist, $postLocation);
$feedUrl = $playlist->getPlaylistVideoFeedUrl();
$videoEntryToAdd = $yt->getVideoEntry(..given id here..);
$newPlaylistListEntry = $yt->newPlaylistListEntry($videoEntryToAdd->getDOM());
$yt->insertEntry($newPlaylistListEntry, $feedUrl);
我得到以下错误:
注意:试图在C:…libraryZendGdataYouTube playlistentry .php中获得非对象的属性
由以下代码引起:
$feedUrl = $playlist->getPlaylistVideoFeedUrl();
var_dump
表示$feed_url
为NULL。并且它显示$playlist
是一个对象Zend_Gdata_YouTube_PlaylistListEntry
,所以我不明白为什么它写了"非对象的属性"
这似乎是API中的某种错误。所以我做了一些变通。这可能看起来很丑,但我没有别的主意。
function grab_dump($var)
{
ob_start();
var_dump($var);
return ob_get_clean();
}
function getPlayListLink($playlist) {
$test = grab_dump($playlist);
$test = strstr($test, "http://gdata.youtube.com/feeds/api/playlists/");
return strstr($test, "' countHint='0'", TRUE);
}
function addVideosToPlaylist($videos_arr, $playlistEntry, $yt) {
$feedUrl = getPlayListLink($playlistEntry);
foreach($videos_arr as $video)
{
$videoEntryToAdd = $yt->getVideoEntry($video);
$newPlaylistListEntry = $yt->newPlaylistListEntry($videoEntryToAdd->getDOM());
$yt->insertEntry($newPlaylistListEntry, $feedUrl);
}
}
就像这样命名:
addVideosToPlaylist($vids_id, $playlist, $yt);