从播放列表中获取所有视频(YouTube API第3版) [英] Get all videos from a playlist (Youtube API v3)

查看:695
本文介绍了从播放列表中获取所有视频(YouTube API第3版)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用新的YouTube API检索的所有视频列表(他们的ID和标题)从一个特定的播放列表。

I'd like to use the new youtube API to retrieve a list of all the videos (their ID's and titles) from a specific playlist.

我需要的ID的分离,这样我可以做一个视频库使用我的网站上的PHP,而不是与播放列表栏只有一个视频。

I need the id's separated so that I can make a "video gallery" using php on my website, instead of only one video with the playlist sidebar.

这已经在我的网站的工作,但由于新的API已经6月4日实施,它不工作了。

This was already working in my website, but since the new API has been implement on June 4th, it's not working anymore.

任何解决方案?
谢谢你。

Any solutions? Thank you.

推荐答案

有是它使用playlistItems.list调用来获取的,你可以用它来获得您所需要的信息视频列表在YouTube API网站PHP示例。

There is a PHP sample on the YouTube API site which uses the playlistItems.list call to get a list of videos which you can use to get the information you require.

http://developers.google.com/youtube/v3/docs/ playlistItems /列表

如果您使用 YouTube的PHP客户端库然后沿着这些路线的东西会让所有的视频​​ID和标题为指定的播放列表:

If you use the YouTube PHP client library then something along these lines will get all video IDs and titles for a specified playlist:

<?php

require_once 'Google/autoload.php';
require_once 'Google/Client.php';
require_once 'Google/Service/YouTube.php';

$client = new Google_Client();
$client->setDeveloperKey('{YOUR-API-KEY}');
$youtube = new Google_Service_YouTube($client);

$nextPageToken = '';
$htmlBody = '<ul>';

do {
    $playlistItemsResponse = $youtube->playlistItems->listPlaylistItems('snippet', array(
    'playlistId' => '{PLAYLIST-ID-HERE}',
    'maxResults' => 50,
    'pageToken' => $nextPageToken));

    foreach ($playlistItemsResponse['items'] as $playlistItem) {
        $htmlBody .= sprintf('<li>%s (%s)</li>', $playlistItem['snippet']['title'], $playlistItem['snippet']['resourceId']['videoId']);
    }

    $nextPageToken = $playlistItemsResponse['nextPageToken'];
} while ($nextPageToken <> '');

$htmlBody .= '</ul>';
?>

<!doctype html>
<html>
  <head>
    <title>Video list</title>
  </head>
  <body>
    <?= $htmlBody ?>
  </body>
</html>

如果您有任何落实的问题,那么请发表您的code作为一个新的问题,有人将能够提供帮助。

If you have any problems implementing then please post your code as a new question and someone will be able to assist.

这篇关于从播放列表中获取所有视频(YouTube API第3版)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆