mheavers
mheavers

Reputation: 30158

using jquery json to get youtube video title

I am trying to get the media:title element from a youtube user's feed using jquery's get json method. I can get a number of the other nodes successfully, but I can't get the media title. Here's the feed url:

http://gdata.youtube.com/feeds/users/armaniexchange/uploads?alt=json-in-script&format=5&callback=showMyVideos

And here's the code I'm using:

<script type="text/javascript">
$(document).ready(function() {
$.getJSON('http://gdata.youtube.com/feeds/users/armaniexchange/uploads?alt=json-in-script&callback=?&max-results=2', function(data) { 
        $.each(data.feed.entry, function(i, item) {
                var updated = item.updated;
                var url = item['media$group']['media$content'][0]['url'];
                var thumb = item['media$group']['media$thumbnail'][0]['url'];
        var media_title = item['media$group']['media$title'];
                var numViews = item['yt$statistics']['viewCount'];

        //$('#feed_container').append('<div class="thumb"><a href="javascript:void(0);" data-link="' + url + '">' + media_title + '</a></div>');

                alert([url, thumb, numViews,media_title].join('\n')); // display it
        });



});
});

Upvotes: 0

Views: 3270

Answers (1)

mVChr
mVChr

Reputation: 50177

In your code, media_title is an object that contains the properties $t with the title you want and another property type with a purpose unknown to me.

I've created a fiddle here to call media_title.$t to show the title you want.

Upvotes: 2

Related Questions