Menampilkan Json Data Youtube Menggunakan Jquery

Struktur Json Youtube :

{
 "kind": "youtube#searchListResponse",
 "etag": "\"0KG1mRN7bm3nResDPKHQZpg5-do/1nOxWHpMHu6ZVPehYb3mK3NRYKY\"",
 "nextPageToken": "CAEQAA",
 "pageInfo": {
  "totalResults": 6094,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#searchResult",
   "etag": "\"0KG1mRN7bm3nResDPKHQZpg5-do/Xy24-MHvFAWZMtIINs5NLB_kT-Q\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "A9CQWhheWq8"
   },
   "snippet": {
    "publishedAt": "2015-08-15T11:30:43.000Z",
    "channelId": "UCYkpDXS8BQt4SqJFWC7hjcA",
    "title": "Nike Ardilla - BINTANG KEHIDUPAN full album",
    "description": "Nike Ardilla - BINTANG KEHIDUPAN full album.",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/A9CQWhheWq8/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/A9CQWhheWq8/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/A9CQWhheWq8/hqdefault.jpg"
     }
    },
    "channelTitle": "Nanangtrisnafc",
    "liveBroadcastContent": "none"
   }
  }
 ]
}


Menampilkan Json Youtube dengan Jquery (contoh kode):


<script type="text/javascript">
$.getJSON("https://www.googleapis.com/youtube/v3/search?q=nike+ardila+full+album&order=rating&part=snippet&maxResults=1&key=[GOOGLE_API_KEY]&prettyPrint=true",function(data){
$.each(data.items, function(i,data){
var div_data =
"<div ><a href='https://www.youtube.com/watch?v="+data.id.videoId+"'>"+data.snippet.title+"</a></div>";
$(div_data).appendTo("#hasil");
});
});
</script>

<div id="hasil"></div>

Contoh Hasil :


Previous
Next Post »