これは、新しいgoogleapiバージョン3に最適なコードです。
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="application/javascript">
$(document).ready(function () {
var channelName = 'PochicaKing';
$.get(
"https://www.googleapis.com/youtube/v3/channels", {
part: 'contentDetails',
forUsername: channelName,
// mine: true,
// access_token: 'ya29.cQEoJbvUmAMT6xJFgDoi4gq0EW8O5Q_9ZqLtNUay0AbNh-mldmNh5mlicarLx00AHxL_O6Vur8M3Bw',
key: 'AIzaSyARSqGexKgNt0BdHUJBXg2pnxMGgYXrszw'
},
function (data) {
$.each(data.items, function (i, item) {
console.log(item);
pid = item.contentDetails.relatedPlaylists.likes;
gitVids(pid);
});
}
);
function gitVids(pid) {
$.get(
"https://www.googleapis.com/youtube/v3/playlistItems", {
part: 'snippet',
maxResults: 5,
playlistId: pid,
key: 'AIzaSyARSqGexKgNt0BdHUJBXg2pnxMGgYXrszw'
},
function (data) {
var output;
$.each(data.items, function (i, item) {
// console.log(item);
vidTitle = item.snippet.title;
vidId = item.snippet.resourceId.videoId;
output = '<li><iframe width="420" height="315"src="http://www.youtube.com/embed/' + vidId + '"></iframe></li>'
$('#results').append(output);
});
}
);
}
});
</script>
</head>
<body>
<ul id="results"></ul>
</body>
</html>