我想在稍后获得所有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>';
最佳答案
使用$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);
}
关于php - Google Youtube API稍后观看,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27951142/