Skip to content

Instantly share code, notes, and snippets.

@douglasmiranda
Created September 21, 2011 15:05
Show Gist options
  • Select an option

  • Save douglasmiranda/1232288 to your computer and use it in GitHub Desktop.

Select an option

Save douglasmiranda/1232288 to your computer and use it in GitHub Desktop.
Get latest videos from Youtube with Jquery (Gdata API)
function show_my_videos(data){
html = ['<ul id="youtube-videos">'];
$(data.feed.entry).each(function(entry){
url = this.link[0].href;
url_thumbnail = this.media$group.media$thumbnail[3].url;
description = this.media$group.media$description.$t;
html.push('<li><a href="'+url+'">');
html.push('<img src="'+url_thumbnail+'" alt="'+description+'">');
html.push('</a></li>');
});
html.push('</ul>');
$("#videos").html(html.join(''));
}
$.ajax({
type: "GET",
url: "http://gdata.youtube.com/feeds/users/[YOUTUBE_USER]/uploads?alt=json-in-script&format=5",
cache: false,
dataType:'jsonp',
success: function(data){
show_my_videos(data);
//If you want to see in console...
// console.log(data);
// console.log(data.feed.entry);
// $(data.feed.entry).each(function(){
// console.log(this.link[0].href);
// console.log(this.media$group.media$thumbnail[3].url);
// console.log(this.media$group.media$description.$t);
// });
}
});
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Latest Youtube Videos</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js"></script>
<script src="get-latest-videos.js"></script>
</head>
<body>
<div id="videos"> <!-- here will be loaded your videos --> </div>
</body>
</html>
@gweatherson
Copy link
Copy Markdown

This is great, thank you. How do I go about limiting the output to only 3 videos?

@jtrollia
Copy link
Copy Markdown

Just add "&max-results=3" to your url o/

@gracehcoote
Copy link
Copy Markdown

Hi there, I was wondering if there was a way to choose a specific video with this rather than just the latest one?

Copy link
Copy Markdown

ghost commented Oct 3, 2014

It Won't work here

@rodoac89
Copy link
Copy Markdown

This solution not work anymore, gdata api is deprecated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment