需要使用jQuery(YouTube API v3)从视频中获取标题的帮助吗

需要使用jQuery(YouTube API v3)从视频中获取标题的帮助吗,jquery,youtube-api,Jquery,Youtube Api,因此,我最近接触到如何使用YouTube API v3,我个人从他们的API中学到了很多-我想知道的是如何获取视频的标题,以便在搜索术语时,它将显示视频的标题 这是我的密码: 一如既往,谢谢你的帮助 function openIt(videoId) { ideVideo = videoId, container = "#abrePlayer"; //open a lightbox, or do something else with the video id. In this ca

因此,我最近接触到如何使用YouTube API v3,我个人从他们的API中学到了很多-我想知道的是如何获取视频的标题,以便在搜索术语时,它将显示视频的标题

这是我的密码:

一如既往,谢谢你的帮助

    function openIt(videoId) {
 ideVideo = videoId,
 container = "#abrePlayer";
 //open a lightbox, or do something else with the video id. In this case, let's create an iframe to play the little bastard.
 iframe = '<iframe width="600" height="400" src="//www.youtube.com/embed/'+ideVideo+'" frameborder="0" allowfullscreen></iframe>';
  $(container).html(iframe)
};

$(document).ready(function() {
  //find using typed word
  $('#searchIt').keyup(function() {
    var itemsPerPage = 20;
    var term = $(this).val();
    var searchUrl = 'http://gdata.youtube.com/feeds/api/videos?q='+term+'&format=5&max-results='+itemsPerPage+'&v=2&alt=jsonc';

    $.ajax({
            type: "GET",
            url: searchUrl,
            dataType: "jsonp",
            success: function(res) {
     $("#resultadosGerais").html('');
        console.log();

        if(res.data.items){
          //if there are items in our response
          var item = res.data.items;

          $.each(item, function(i, data) {
            var videoId = data.id;
            var thumb = "https://i.ytimg.com/vi/" + videoId + "/default.jpg";

            var showThis = '<div id=\"result\" onClick=\"openIt(\''+ videoId + '\');"> <img src=\"' + thumb + '\" /><p id=\"media-header\">'+videoId+'</p></div><br />';
            $("#resultadosGerais").append(showThis);
          });
        } else {
          $("#resultadosGerais").append('No Results Found');
        }
      }})
  });
});
函数openIt(videoId){
ideVideo=videoId,
container=“#abrePlayer”;
//打开一个灯箱,或者使用视频id执行其他操作。在这种情况下,让我们创建一个iframe来播放这个小混蛋。
iframe='';
$(容器).html(iframe)
};
$(文档).ready(函数(){
//使用键入的单词查找
$('#searchIt').keyup(函数(){
var itemsPerPage=20;
var term=$(this.val();
var searchUrl=http://gdata.youtube.com/feeds/api/videos?q=“+term+”&format=5&max results='+itemsPerPage+'&v=2&alt=jsonc';
$.ajax({
键入:“获取”,
url:searchUrl,
数据类型:“jsonp”,
成功:功能(res){
$(“#resultadosGerais”).html(“”);
console.log();
if(资源数据项){
//如果我们的回复中有项目
var item=res.data.items;
$。每个(项目、功能(i、数据){
var videoId=data.id;
变量thumb=”https://i.ytimg.com/vi/“+videoId+”/default.jpg”;
var showThis='

'+videoId+'


'; $(“#resultadosGerais”).append(showThis); }); }否则{ $(“#resultadosGerais”).append('No Results Found'); } }}) }); });
您可以使用示例URL轻松分析从youtube API获得的响应,例如

这将返回一个JSON数组,您可以在预览中显示该数组。我相信你想在那里显示标题而不是ID

var showThis = '<div id=\"result\" onClick=\"openIt(\''+ videoId + '\');"> <img src=\"' + thumb + '\" /><p id=\"media-header\">'+data.title+'</p></div><br />';
        $("#resultadosGerais").append(showThis);
var showThis='

'+data.title+'


; $(“#resultadosGerais”).append(showThis);
这里的关键是
data.title
,它包含视频的标题