jquery youtube检索描述

时间:2013-01-04 17:49:58

标签: jquery json youtube

如何添加此代码,以便在iframe中提取说明以及标题和视频?

JavaScript的:

$(function() {
    var htmlString = "<ul>";
    $.getJSON('http://gdata.youtube.com/feeds/users/(MY USER)/uploads?alt=json-in-script&callback=?&max-results=3', function(data) {
           $.each(data.feed.entry, function(i, item) {                                     
                   var title = item['title']['$t'];
                    var video = item['id']['$t'];
                    video_link = video.replace('http://gdata.youtube.com/feeds/videos/','http://www.youtube.com/watch?v=');
                    video_object = video.replace('http://gdata.youtube.com/feeds/videos/','http://www.youtube.com/v/');
                    htmlString +='<li><p id="video_title">' + title + '</p><object width="600" height="450"><param name="movie" value="' + video_object + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="' + video_object + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="600" height="450"><noembed>Browser does not support video</noembed></embed></object></li>';
            });
            $('#videos').html(htmlString + "</ul>");
    });

HTML:

<div id="videos"></div>

2 个答案:

答案 0 :(得分:1)

尝试:

var desc = item.media$group.media$description.$t;

答案 1 :(得分:0)

如果您在getJson中读取了url,您会注意到url需要一个用户名和一个回调方法。你错过了两个。

http://gdata.youtube.com/feeds/users/ (我的用户) /上传?alt = json-in-script&amp; 回调 =?&amp; max-results = 3

您可以在他们的指南上阅读有关如何使用youtubes api的更多信息 https://developers.google.com/youtube/2.0/developers_guide_json