【问题标题】:Google Youtube API watch laterGoogle Youtube API 稍后观看
【发布时间】:2015-03-13 02:53:52
【问题描述】:

我想使用 PHP API 3.0 获取我所有的 youtube 观看稍后视频列表,但似乎我们无法使用 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>';

【问题讨论】:

    标签: php youtube google-api


    【解决方案1】:

    使用$youtube-&gt;channels-&gt;listChannels 而不是$youtube-&gt;channelSections-&gt;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);
    }
    

    【讨论】:

      猜你喜欢
      • 2017-05-18
      • 2014-03-25
      • 2011-09-03
      • 2018-10-09
      • 1970-01-01
      • 2019-03-30
      • 2016-07-14
      • 1970-01-01
      • 2017-02-27
      相关资源
      最近更新 更多