从数组的链接创建YouTube播放列表


create youtube playlist from array of links

嗨,我可以做一个PHP函数,在那里我可以传递一个数组的YouTube链接,它创建一个播放列表在YouTube上为特定的用户,我读过YouTube文档,但仍然不能弄清楚。https://developers.google.com/youtube/2.0/developers_guide_php#Adding_a_Playlist_Video在文档中显示以下代码。

    $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();
}

我不是专家,但我认为这是你正在寻找的:

//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显然应该是包含ytvideo ' id '的一维数组。