假设您能够使用 PHP 进行编程,我建议您从小处着手,从 YouTube Data API Overview、PHP Quickstart 和 PHP Client Library: Getting Started 逐步进行。无论如何,the reference documentation 是你最好的朋友——只是你必须熟悉它。
您将使用 PHP 客户端库 code,从而将其克隆到本地计算机。
暂时不用OAuth认证,只从谷歌的developers console和API key获取与API的PlaylistItems endpoint一起使用,查询给定的channel's uploads list。
Github 上有一些sample code 用于获取用户的上传列表,但该代码相当陈旧并且很可能存在问题(它还使用 OAuth 授权,我已经建议您不要打扰)。这是该代码的基本部分(我对其进行了一些修改:将 'mine' => 'true' 替换为 'id' => $YOUR_CHANNEL_ID;但您必须测试此代码):
try {
// Call the channels.list method to retrieve information about the
// currently authenticated user's channel.
$channelsResponse = $youtube->channels->listChannels('contentDetails', array(
'id' => $YOUR_CHANNEL_ID,
));
$htmlBody = '';
foreach ($channelsResponse['items'] as $channel) {
// Extract the unique playlist ID that identifies the list of videos
// uploaded to the channel, and then call the playlistItems.list method
// to retrieve that list.
$uploadsListId = $channel['contentDetails']['relatedPlaylists']['uploads'];
$playlistItemsResponse = $youtube->playlistItems->listPlaylistItems('snippet', array(
'playlistId' => $uploadsListId,
'maxResults' => 50
));
$htmlBody .= "<h3>Videos in list $uploadsListId</h3><ul>";
foreach ($playlistItemsResponse['items'] as $playlistItem) {
$htmlBody .= sprintf('<li>%s (%s)</li>', $playlistItem['snippet']['title'],
$playlistItem['snippet']['resourceId']['videoId']);
}
$htmlBody .= '</ul>';
}
} catch (Google_Service_Exception $e) {
$htmlBody = sprintf('<p>A service error occurred: <code>%s</code></p>',
htmlspecialchars($e->getMessage()));
} catch (Google_Exception $e) {
$htmlBody = sprintf('<p>An client error occurred: <code>%s</code></p>',
htmlspecialchars($e->getMessage()));
}
从一开始,您就必须知道the quota system API 正在实施。根据使用模式,配额可能会将rather tight limits 置于允许用户在 API 的各个端点上进行的调用次数上。 Google 的开发者控制台会随时向您显示您当前的配额。
最后,一个用于调试应用的有用工具:APIs Explorer。它允许您调用 API 端点并查看它们各自的 JSON 响应文本。