从链接数组创建youtube播放列表

时间:2012-12-30 12:44:39

标签: php arrays youtube youtube-api playlist

嗨,我可以制作一个PHP函数,我可以传递一组youtube链接,它在youtube中为某个用户创建一个播放列表,我已阅读youtube文档,但仍然无法弄清楚。 https://developers.google.com/youtube/2.0/developers_guide_php#Adding_a_Playlist_Video 在doc上它显示以下代码。

    $newPlaylist = $yt->newPlaylistListEntry();
$newPlaylist->summary = $yt->newDescription()->setText('description of my new playlist');
$newPlaylist->title = $yt->newTitle()->setText('title of my new playlist');
// post the new playlist
$postLocation = 'http://gdata.youtube.com/feeds/api/users/default/playlists';
try {
  $yt->insertEntry($newPlaylist, $postLocation);
} catch (Zend_Gdata_App_Exception $e) {
  echo $e->getMessage();
}

1 个答案:

答案 0 :(得分:0)

我不是专家,但我认为这就是你要找的东西:

//Make a loop to go over all of the values within the array
     for ($i = 0; $i <= count($array); $i++){
$postUrl = $playlistToAddTo->getPlaylistVideoFeedUrl();
// video entry to be added
$videoEntryToAdd = $yt->getVideoEntry($array[i]);

// create a new Zend_Gdata_PlaylistListEntry, passing in the underling DOMElement of the VideoEntry
$newPlaylistListEntry = $yt->newPlaylistListEntry($videoEntryToAdd->getDOM());

// post
try {
  $yt->insertEntry($newPlaylistListEntry, $postUrl);
} catch (Zend_App_Exception $e) {
  echo $e->getMessage();
}
}

变量$array显然应该是包含ytvideos'ID'的一维数组。希望有所帮助。

相关问题