php - Google Youtube API稍后观看

标签 php youtube google-api

我想在稍后获得所有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/

相关文章:

curl - 尝试刷新访问 token 时出现 Google Oauth2 invalid_grant 错误

php - 如何使用 PHP 正确创建此 XML

php - PHP 中的未定义索引和 MYSQL 中的数据类型 POINT

ruby-on-rails - youtube 嵌入链接未显示在 Rails View 中

javascript - 如何确定用户是否关闭了 google auth2.signIn() 窗口?

angular - Google API 回调更改后 View 未更新

php - 在页面加载时加载 gif

php - 如何使 Php stream_socket 保持事件状态?

api - YouTube 数据 API V3 未从 channel ID 返回直播

javascript - 动态评论功能代码