這是新的谷歌API版本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>
喜Bhaiya在你的指導我已經搜查,現在我要把它,感謝您的幫助,我會嘗試... – Udhikriman
如果我只想爲gdata.youtube.com獲得JSON字符串響應,那麼我需要寫什麼url – Udhikriman
@Udhikriman:你在這裏發送的「+ username +」用於獲取json –