<script type= "text/javascript">
var url = "http://gdata.youtube.com/feeds/api/videos/VA770wpLX-Q?v=2&alt=json-in-script&callback=";
var title;
var description;
var viewcount;
var views;
var author;
$.getJSON(url,
function(data){
title = data.entry.title.$t;
description = data.entry.media$group.media$description.$t;
viewcount = data.entry.yt$statistics.viewCount;
views = numberFormat (viewcount);
author = data.entry.author[0].name.$t;
listInfo (title,description,author,views);
});
</script>
So thats my code to get information from a single video, after the info is received it calls this function to display it:
<script type="text/javascript">
function listInfo (title,description,author,views) {
var html = ['<dl>'];
html.push('<dt>','<span class="titleStyle">', title,'</span><span class="descriptionStyle">',description, '</span><span class="authorStyle">',author,'</span><span class="viewsStyle">',' Views:',views,'</span></dt>');
html.push('</dl>');
document.getElementById("agenda").innerHTML = html.join("");
}
function numberFormat(nStr,prefix){
var prefix = prefix || '';
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1))
x1 = x1.replace(rgx, '$1' + ',' + '$2');
return prefix + x1 + x2;
}
</script>
After that it puts the definition List into a div, which I have inside a table
<table width="485"><tr><td><div id="agenda"></div></td></tr></table>
all of this information is found in the body, I can’t seem to get it to work, I’ve been trying for a week now, and I can’t find any way to make it work
Since the youtube API does not allow more than 50 comments to be returned on a single request, you’ll need to add a URL parameter called “start-index”, which tells youtube that you want to get comments from there onwards. Below is an example. I’ve made it so that as long as the response JSON returns 50 comments, it calls the function again for the next 50 comments.
If you have any more questions or you get stuck with this code, don’t hesitate to ask again 🙂
Good luck,
Tom