<?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...
你能帮助我吗?
答案 0 :(得分:1)
如果你打电话:
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