A
A
Alex Goncharov2018-08-09 09:31:51
YouTube
Alex Goncharov, 2018-08-09 09:31:51

How to get title from Youtube JSON file?

Hey! I understand JS, I can’t figure out how to get the title and date from the received JSON and display it under each video

Script to randomly display 4 videos per page

<script>
 Array.prototype.shuffle = function() {
  var i = this.length, j, temp;
  if ( i == 0 ) return this;
  while ( --i ) {
     j = Math.floor( Math.random() * ( i + 1 ) );
     temp = this[i];
     this[i] = this[j];
     this[j] = temp;
  }
  return this;
}
jQuery.getJSON('https://www.googleapis.com/youtube/v3/search?key=AIzaSyB2OIY025pEFAwZeskj-KvcnCBG_5XfzY0&channelId=UCy5E4aFQdeX9cvRC4sttsSw&part=snippet,id&order=date&maxResults=20', function(data2) {
   	new_arr = [];


  jQuery.each(data2['items'] , function( index, value ) {
 		new_arr[index] = data2['items'][index]['id']['videoId'];
 		
  });
  

   new_arr = new_arr.shuffle();
    //alert(new_arr);
  jQuery.each(new_arr , function( index2, value2 ) {
 	 
    if(index2 < 4  ){
      //alert( new_arr['index2']);
       jQuery('.posts-loop').append('<div class="yourandom"><iframe style="float:left;width:48%; margin:1%" src="https://www.youtube.com/embed/'+value2+'" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe></div>');
      //$('body').append("https://www.youtube.com/watch?v="+value2+"<br>");
    }
  });

  
});


</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
ixon, 2018-08-09
@calirails

json.items[0].snippet.title;// TItle первого элемента
json.items[1].snippet.title;// TItle второго элемента
json.items[2].snippet.title;// TItle третьего элемента
json.items[i].snippet.title;// TItle i-го элемента

Where json is your json-formatted response received
from googleapis.com .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question