Created
September 21, 2011 15:05
-
-
Save douglasmiranda/1232288 to your computer and use it in GitHub Desktop.
Get latest videos from Youtube with Jquery (Gdata API)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
// }); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
Just add "&max-results=3" to your url o/
Hi there, I was wondering if there was a way to choose a specific video with this rather than just the latest one?
It Won't work here
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
This is great, thank you. How do I go about limiting the output to only 3 videos?