PHP: YouTube v3 API...从稍后观看列表中检索最后 50 个视频并将它们添加到播放列表
PHP: YouTube v3 API... Retrieve last 50 videos from Watch Later list and add them to a 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>
如何为Watch Later Playlist
做呢?已经有了 API 键。
然后,对于任何 videoId -> insert the video in another playlist...
你能帮帮我吗?
如果您致电:
GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&mine=true&key={YOUR_API_KEY}
您可以获得稍后观看列表的 playlistId
(在 watchLater
下)。您需要进行身份验证才能获得结果。如果这是一次性的事情,那么使用 API 浏览器:
https://developers.google.com/youtube/v3/docs/channels/list。
获得 playlistId
后,您可以使用问题中的代码从列表中获取视频(和视频 ID)。在此处进行调用示例之前,您需要添加 OAuth 身份验证代码:
https://developers.google.com/youtube/v3/code_samples/php
要将视频上传到新的播放列表,API 文档中有一个 PHP 示例:
https://developers.google.com/youtube/v3/code_samples/php#resumable_uploads
<?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>
如何为Watch Later Playlist
做呢?已经有了 API 键。
然后,对于任何 videoId -> insert the video in another playlist...
你能帮帮我吗?
如果您致电:
GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&mine=true&key={YOUR_API_KEY}
您可以获得稍后观看列表的 playlistId
(在 watchLater
下)。您需要进行身份验证才能获得结果。如果这是一次性的事情,那么使用 API 浏览器:
https://developers.google.com/youtube/v3/docs/channels/list。
获得 playlistId
后,您可以使用问题中的代码从列表中获取视频(和视频 ID)。在此处进行调用示例之前,您需要添加 OAuth 身份验证代码:
https://developers.google.com/youtube/v3/code_samples/php
要将视频上传到新的播放列表,API 文档中有一个 PHP 示例:
https://developers.google.com/youtube/v3/code_samples/php#resumable_uploads