2015-01-14 5 views
1

Я хотел бы получить все мои просмотры видео youtube позже с PHP API 3.0, но похоже, что мы не можем получить доступ к ним с помощью PHP и API 3. Кто-нибудь еще это сделал?Google Youtube API смотреть позже

Мой код сейчас

// 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>'; 

ответ

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); 
} 
Смежные вопросы