如何获取和分类视频ID为Youtube Data APi v3播放列表视频的视频

时间:2018-12-06 12:31:08

标签: javascript jquery youtube-data-api

我对JavaScript和jQuery相对较新,我正在从事这个项目,因此我希望单击列表时一一选择videoID的输出。

从API获取数据后

var videoUrl = item.snippet.resourceId.videoId;
function search(){

  //alert('we are rolling');
  //Clear search results

  $('#results').html('');
  $('#player').html('');
  $('#ytiframe').html('');

  //get form input
  q = $('UUcGEts4Au0PdKuRkKA7OhLQ').val();


  // Run Get Request on API

  //alert(q);

  $.get("https://www.googleapis.com/youtube/v3/playlistItems",{
        maxResults: '30',
        part: 'snippet,contentDetails',
        playlistId: 'UUcGEts4Au0PdKuRkKA7OhLQ',
        type: 'video',
        key: 'AIzaSyBohssohwRjfAIgsIwEIbgMTcLPQfTKwN4'},
      
        
    );
}

//Build Output

function getOutput(item){
  //var videoId = item.id.videoId;
  var title = item.snippet.title;
  var description = item.snippet.description;
  var thumb = item.snippet.thumbnails.medium.url;
  var channelTitle = item.snippet.channelTitle;
  var videoDate = item.snippet.publishedAt;
  var videoUrl = item.snippet.resourceId.videoId;
  var edited = description.substr(0,100);
  var position = item.snippet.position;
  
  var videoUrl2 = [videoUrl,','];

  


 

  // get url
  function getUrl(){
    if (document.getElementById(position).clicked == true && position.length == 9) {
    	$('#player').show();

    	
    	
    }else	{
    	$('#player').hide();
    };
    
  }
  
  //Build Output String

  var output = '<li id="'+position+'" data-video-id="'+videoUrl+'"">'+
  				'<div id="'+position+'"><iframe  width="350" height="210" src="https://www.youtube.com/embed/'+videoUrl+'" '+
              'frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" '+
              'allowfullscreen>'+
              '</iframe>'+  
              '<h6>'+title+'</h6>'+            
             // '<p id="edited">'+edited+'</p> </div>'+
			  '</li>'+
			  // '<div class="clearfix"></div>'+
			  ''; 


document.write(videoUrl2[0],'  ,  ');




    
 
}
 <div id="result" class="col-md-12">
      
      <ul id="results"></ul>
      

</div>

输出是这样的

  

cycQsdkLLu0,DhII_rX4iFc,FKZzWqEVtBY,oxAI8VQQZGo,SPELNgm3cxg,   r-S78rqoZBs,yRtYOST-Hns,D6CSPB59khI,OA9NHOSe5Bc,Vk0ADDcpvQM,   MvSWIR5UeSQ,bBEccd3-lCg,t67ELfDf45U,_jD-zI7vXdc,D3MynqafKKA,   K81Rag_GdWo,wxsOUuPvqXs,ZDK_16l18t4,YOVdpHlPvV4,uFc6YjXoXlU,   CgsCltoy_iY,7xQrpli_BTg,43VT5eoTk_0,S7SoN4FLsR0,W2mQ0SGbL1g,   GUUIGHUIPUo,30cSlv9e9L4,pHh3pKcLDrQ,

我希望一次选择一个videoUrl,并将其投放到iframe或API iframe播放器中。

0 个答案:

没有答案