javascript - YouTube user feed parsing from JSON -
i trying make script json feed of specific user latest 2 uploads on youtube. tried use script
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script> <script type="text/javascript"> // set variables needed query var url = "https://gdata.youtube.com/feeds/api/users/"; var username = "myusername"; var jsonformat = "/uploads?v=2&alt=jsonc&max-results=2"; // construct json feed of youtube user's channel var ajaxurl = url + username + jsonformat; // last videos of youtube account, parse html code $.getjson(ajaxurl, function(data){ var htmlstring = ""; $.each(data.items, function(i,item){ // here's piece html htmlstring += '<iframe class="videos" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/'; htmlstring += item.id; htmlstring += '?autoplay=0" frameborder="0"></iframe>'; }); // pop our html in #videos div $('#videos').html(htmlstring); });
i have been using similar script parsing flickr's json , it's working fine.. might going wrong youtube's feed?
you've placed api return youtube javascript object data
, keep in mind youtube encapsulates returned object in object called data
.
therefore, in line 14, when begin iterating through data set:
$.each(data.items, function(i,item){
... should be:
$.each(data.data.items, function(i,item){
here code (corrected) placed jsfiddle: http://jsfiddle.net/up3w7/
Comments
Post a Comment