API Dailymotion et JQuery, afficher les 100 news les plus consultées sur Dailymotion durant les dernières 24h
<!DOCTYPE html>
<!-- Source code from http://ntic974.blogspot.com 13/07/2014 -->
<html>
<head>
<!--<script src="./jquery-2.1.1.js"></script>-->
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script>
$(document).ready(function(){
$.getJSON("https://api.dailymotion.com/videos?fields=url&channel=news&sort=visited-today&limit=100",
function( data ) {
console.log(data);
var items = [];
$.each( data, function( key, val ) {
console.log(key);
//items.push( "<li id='" + key + "'>key = " + key + " : val = " + val + "</li>" );
if (key=='list'){
//items.push("List detected");
$.each(val, function(subkey,subval){
console.log(subkey + ":" + subval);
//items.push( "<li id='" + subkey + "'>subkey = " + subkey + " : subval = " + subval + "</li>" );
$.each(subval, function(subkey2, subval2){
console.log(subkey2 + ":" + subval2);
//items.push( "<li id='" + subkey2 + "'>subkey2 = " + subkey2 + " : subval2 = " + subval2 + "</li>" );
if (subkey2=='views_last_day'){
items.push("views_last_day = " + subval2 + "<br/>");
}
if (subkey2=='url'){
items.push("<a href='" + subval2 + "'>" + subval2 + "</a><br/>");
}
});
});
}
});
$( "<ul/>", {
"class": "my-new-list",
html: items.join( "" )
}).appendTo( "body" );
});
});
</script>
</head>
<body>
</body>
</html>