有人可以帮我从youtube频道获取视频吗?
以下是HTML代码:
<!doctype html>
<html>
<head>
<title>My Uploads</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="js/script.js"></script>
</head>
<body>
<div id="container">
<h1> Videos </h1>
<ul id="results"></ul>
</div>
</body>
</html>
以下是我的JavaScript:
var channelName = 'UCcPHkNcLFjenlxtMxEw_YZQ';
$(document).ready(function() {
$.get(
"https://www.googleapis.com/youtube/v3/channels",{
part: 'contentDetails',
forUsername: channelName,
key: 'API Key'},
function(data){
$.each(data.items, function(i,item){
console.log(item);
pid = item.contentDetails.relatedPlaylists.uploads;
getVids(pid);
})
}
);
function getVids(pid){
$.get(
"https://www.googleapis.com/youtube/v3/playlistItems",{
part: 'snippet',
maxResults: 10,
playlistId: pid,
key: 'API Key'},
function(data){
var output;
$.each(data.items, function(i, item){
console.log(item);
videTitle = item.snippet.title;
//videoId = item.snippet.resourceId.videoId;
output = '<li>'+videTitle+'</li>';
console.log(output);
//$('#results').append(output);
})
}
);
}
});
我需要指导才能将YouTube频道的视频发送到网页。
提前致谢。