Xml 从播放列表中获取所有视频(Youtube API v3)

Xml 从播放列表中获取所有视频(Youtube API v3),xml,api,video,youtube,playlists,Xml,Api,Video,Youtube,Playlists,我想使用新的youtube API从特定的播放列表中检索所有视频(它们的ID和标题)的列表 我需要分开id,这样我就可以在我的网站上使用php制作一个“视频库”,而不是只有一个带有播放列表边栏的视频 这已经在我的网站上起作用了,但是自从6月4日新的API被实现后,它就不再起作用了 有什么解决办法吗? 谢谢。YouTube API网站上有一个PHP示例,它使用playlitems.list调用获取视频列表,您可以使用该列表获取所需信息 如果使用,则以下内容将获得指定播放列表的所有视频ID和标题:

我想使用新的youtube API从特定的播放列表中检索所有视频(它们的ID和标题)的列表

我需要分开id,这样我就可以在我的网站上使用php制作一个“视频库”,而不是只有一个带有播放列表边栏的视频

这已经在我的网站上起作用了,但是自从6月4日新的API被实现后,它就不再起作用了

有什么解决办法吗?
谢谢。

YouTube API网站上有一个PHP示例,它使用playlitems.list调用获取视频列表,您可以使用该列表获取所需信息

如果使用,则以下内容将获得指定播放列表的所有视频ID和标题:

<?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>

视频列表

如果您在实现时遇到任何问题,请将代码作为新问题发布,有人会提供帮助。

YouTube API网站上有一个PHP示例,它使用playlitems.list调用获取视频列表,您可以使用该列表获取所需信息

如果使用,则以下内容将获得指定播放列表的所有视频ID和标题:

<?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>

视频列表

如果您在实现时遇到任何问题,请将代码作为新问题发布,有人会提供帮助。

YouTube API网站上有一个PHP示例,它使用playlitems.list调用获取视频列表,您可以使用该列表获取所需信息

如果使用,则以下内容将获得指定播放列表的所有视频ID和标题:

<?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>

视频列表

如果您在实现时遇到任何问题,请将代码作为新问题发布,有人会提供帮助。

YouTube API网站上有一个PHP示例,它使用playlitems.list调用获取视频列表,您可以使用该列表获取所需信息

如果使用,则以下内容将获得指定播放列表的所有视频ID和标题:

<?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>

视频列表

如果您在实现过程中遇到任何问题,请将您的代码作为新问题发布,有人会提供帮助。

谢谢!成功了。要导入一个完整的库来做一些过去很简单的事情真是太糟糕了。。。但是好。。。您还应该编辑您的答案,在其他答案之前包含“require_once'Google/autoload.php';”,否则代码将无法工作。很高兴它能工作。已添加您建议的要求。我的代码中确实有它,但我认为这是我(新重新安装的)安装程序的一个特点,所以没有将它复制到so。谢谢!成功了。要导入一个完整的库来做一些过去很简单的事情真是太糟糕了。。。但是好。。。您还应该编辑您的答案,在其他答案之前包含“require_once'Google/autoload.php';”,否则代码将无法工作。很高兴它能工作。已添加您建议的要求。我的代码中确实有它,但我认为这是我(新重新安装的)安装程序的一个特点,所以没有将它复制到so。谢谢!成功了。要导入一个完整的库来做一些过去很简单的事情真是太糟糕了。。。但是好。。。您还应该编辑您的答案,在其他答案之前包含“require_once'Google/autoload.php';”,否则代码将无法工作。很高兴它能工作。已添加您建议的要求。我的代码中确实有它,但我认为这是我(新重新安装的)安装程序的一个特点,所以没有将它复制到so。谢谢!成功了。要导入一个完整的库来做一些过去很简单的事情真是太糟糕了。。。但是好。。。您还应该编辑您的答案,在其他答案之前包含“require_once'Google/autoload.php';”,否则代码将无法工作。很高兴它能工作。已添加您建议的要求。我的代码中确实有它,但我认为这是我(新重新安装的)设置的一个特点,所以没有将它复制到so。