I’d like to extract the last video (only video), with title, description, etc.
I am using JSON Data API from YouTube Data API and using the Video Upload By User Feed in order to get the data.
I got from youtube a JSON (object?) about my Youtube’s space and tried to read the JSON text, but its a suicide.
My code is :
<div id="ytContent"></div>
<script type="text/javascript">
function showMyVideos(data) {
var feed = data.feed;
var entries = feed.entry || [];
for (var i = 0; i < entries.length; i++) {
var entry = entries[i];
var title = entry.title.$t;
$('#ytContent').append(title + "<br />");
}
}
</script>
<script type="text/javascript" src="http://gdata.youtube.com/feeds/users/MYUSERNAME/uploads?alt=json-in-script&format=5&callback=showMyVideos"></script>
but if I try to do :
var p = eval("(" + data + ")");
alert(p);
I can’t get a right parser. Why? How can I parse my JSON? I just need to understand which field I can use in order for me to get the last video from the feed. Also, hints/tips on getting the last video will also be helpful.
Thanks
You don’t need to parse the data, it is already parsed.
The url inside your
scripttags gets rendered into a function call, passing the data object as a parameter:showMyVideos({ /* data object */ });.Your problem is that you are trying to access the
entryfield in the data you are receiving (var entries = feed.entry || []), but there is no such field indata.feed: