Skip to content Skip to sidebar Skip to footer

Embed Most Recent YouTube Videos On Website?

I am currently learning web development and I am friends with someone that is fairly large on YouTube, so I offered to create him a website for free in order to build my portfolio

Solution 1:

Your code works fine if you make some adjustments.

First, to get the last 8 videos, you need to include that number in your 'query url' as max-results:

                                                                 here
                                                                   ▼
https://gdata.youtube.com/feeds/api/users/VEVO/uploads?max-results=8&orderby=published&v=2&alt=jsonc&callback=showVideo

Then, to show every video, instead of an if statement, you need to have a loop (for loop here), and to .append() each video instead of replacing the entire content each time with .html():

function showVideo(response) {
    if(response.data && response.data.items) {
        var items = response.data.items;
        // the loop i'm talking about
        for(var i=0, l=items.length; i<l; i++){
            var item = items[i];
            var videoid = "http://www.youtube.com/embed/"+item.id;
            console.log("Latest ID: '"+videoid+"'");
            var video = "<iframe width='420' height='315' src='"+videoid+"' frameborder='0' allowfullscreen></iframe>";
            // here, add the video to the container
            $('#static_video').append(video);
        }
    }
}

Solution 2:

This will embed your "uploads" playlist. If you want your most recent video to play, just go to your channel and sort your uploads by most recent. Here's the code:

<iframe src="https://www.youtube.com/embed/videoseries?list=UUB8OUG89o0QWqmJ2lfzdyIg" seamless allowfullscreen></iframe>

UUB8OUG89o0QWqmJ2lfzdyIg is the unique id of my personal uploads playlist. To get the unique id of your playlist, take your unique channel id and simply change the C to a U.

UCB8OUG89o0QWqmJ2lfzdyIg // channel id
UUB8OUG89o0QWqmJ2lfzdyIg // uploads playlist id

All the Youtube playlists have ids, you just need to find them. You can alternatively find a playlist id by playing the full playlist with the "Play All" button. This will play the entire playlist on Youtube and you can copy the id out of the page url.


Post a Comment for "Embed Most Recent YouTube Videos On Website?"