如何通过JavaScript和JSON从YouTube获取视频的视图和描述 [英] How to get the views and description of the video from the YouTube through JavaScript and JSON

查看:68
本文介绍了如何通过JavaScript和JSON从YouTube获取视频的视图和描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过JavaScript和JSON从YouTube获取视频的观看和描述





How to get the views and description of the video from the YouTube through JavaScript and JSON


<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title></title>

  <script type='text/javascript' src='http://code.jquery.com/jquery-1.8.3.js'></script>



<script type='text/javascript'>//<![CDATA[
$(window).load(function(){
function LoadVids(startindex){
if (typeof startindex === "undefined" || startindex===null) startindex = 1;
var maxresults = 10;

var playListURL = 'http://gdata.youtube.com/feeds/api/playlists/PL3B8939169E1256C0?orderby=published&v=2&alt=json&&start-index=' + startindex + '&max-results=' + maxresults;
var videoURL= 'videos.html?name=';
$.getJSON(playListURL, function(data) {
    var list_data="";
    $.each(data.feed.entry, function(i, item) {
        var feedTitle = item.title.$t;
        var feedURL = item.link[1].href;
        var fragments = feedURL.split("/");
        var videoID = fragments[fragments.length - 2];
        var vid = item.media$group.yt$videoid.$t;
        var url = videoURL + videoID;
        var vidtitle = item.title.$t;
        var vidviews = item.views.$t;
        var content = item.description.$t;
        var thumb = "http://img.youtube.com/vi/"+ videoID +"/default.jpg";
        list_data += '<div><a href="'+ url +'" title="'+ feedTitle +'"><img alt="'+ feedTitle+'" src="'+ thumb +'"</a>' + vidtitle +"<br/>"+ vidviews +"<br/>"+ content + '</div>';
    });
    $(list_data).appendTo(".cont");
});
}


//
$( document ).ready(function() {
 LoadVids(1); // call on load more click
});
});//


</script>
</head>
<body>
<ul  class="cont">
</ul>

</body>
</html>

推荐答案

(窗口).load(function() {
函数LoadVids(startindex){
if(typeof startindex ===undefined|| startindex === null)startindex = 1;
var maxresults = 10;

var playListURL ='http://gdata.youtube.com/feeds/api/playlists/PL3B8939169E1256C0?orderby=published&v=2&alt=json&&start-index='+ startindex +'& ; max-results ='+ maxresults;
var videoURL ='videos.html?name =';
(window).load(function(){ function LoadVids(startindex){ if (typeof startindex === "undefined" || startindex===null) startindex = 1; var maxresults = 10; var playListURL = 'http://gdata.youtube.com/feeds/api/playlists/PL3B8939169E1256C0?orderby=published&v=2&alt=json&&start-index=' + startindex + '&max-results=' + maxresults; var videoURL= 'videos.html?name=';


.getJSON(playListURL,function(data){
var list_data =;
.getJSON(playListURL, function(data) { var list_data="";


.each(data.feed.entry,function(i,item){
var feedTitle = item.title。
.each(data.feed.entry, function(i, item) { var feedTitle = item.title.


这篇关于如何通过JavaScript和JSON从YouTube获取视频的视图和描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆