我希望以后的所有youtube观看视频列表与PHP API 3.0相同,但似乎我们无法通过PHP和API 3访问这些视频列表。有没有人已经完成了它?
我现在的代码
// Call the YouTube Data API's channelSections.list method to retrieve your channel sections.
$listResponse = $youtube->channelSections->listChannelSections('snippet,contentDetails', array('mine' => true));
$channelSections = $listResponse['items'];
$htmlBody .= "<h2>Sections Shuffled</h2><ul>";
foreach ($channelSections as $channelSection) {
// Each section in the list of shuffled sections is sequentially
// set to position 0, i.e. the top.
$channelSection['snippet']['position'] = 0;
// Call the YouTube Data API's channelSections.update method to update a channel section.
$updateResponse = $youtube->channelSections->update('snippet,contentDetails', $channelSection);
$htmlBody .= sprintf('<li>%s "%s"</li>',
$updateResponse['id'], $updateResponse['snippet']['title']);
}
$htmlBody .= '</ul>';
答案 0 :(得分:1)
使用$youtube->channels->listChannels
代替$youtube->channelSections->listChannelSections
// Get all channels of current user
$channels = $youtube->channels->listChannels('contentDetails', ['mine' => true]);
// Get watch later playlists ID from the first channel
$watchLaterListId = $channels[0]->getContentDetails()->getRelatedPlaylists()->getWatchLater();
// Get videos from the playlist
$videos = $youtube->playlistItems->listPlaylistItems('contentDetails', ['playlistId' => $watchLaterListId]);
// Loop videos
foreach($videos as $video)
{
// This is the global video ID.
$globalVideoId = $video->getContentDetails()->getVideoId();
// This is unique ID of this video on the playlist. The one you need to interact with the playlist
$playlistVideoId = $video->id;
//i.e: To remove this video from the playlist
$youtube->playlistItems->delete($playlistVideoId);
}