Google YouTube API Retrieving Video Feeds From YouTube Using Java
Posted by blogmeister on
March 26, 2008
Share the post "Google YouTube API Retrieving Video Feeds From YouTube Using Java"
To retrieve list of video feeds from a user from Google, include the init() method from this post. Then use the method below to get the title of the video and the URL. This sample code retrieves the video feed list of the logged-in user. To retrieve the list of video feeds for other users, check the user guide.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
public static Vector getUserVideos() throws Exception { URL feedUrl = new URL("http://gdata.youtube.com/feeds/api/users/default/uploads"); VideoFeed videoFeed = service.getFeed(feedUrl, VideoFeed.class); String title = videoFeed.getTitle().getPlainText(); List videoEntries = videoFeed.getEntries(); Vector vect = new Vector(); YouTubeVideoProperties ytvp = null; if (videoEntries.size() == 0) { System.out.println("This feed contains no entries."); return; } for (VideoEntry entry : videoEntries) { System.out.println("title="+entry.getTitle().getPlainText()); YouTubeMediaGroup mediaGroup = entry.getMediaGroup(); if (mediaGroup != null) { MediaPlayer player = mediaGroup.getPlayer(); if (player != null) System.out.println("video url="+player.getUrl()); } } return vect; } |
To get an image of the video thumbnail like what you in the YouTube site, get the String after this URL, http://www.youtube.com/watch?v=GET_THIS_STRING
Then use that same string to get the thumbnail image of the video using this URL, http://i.ytimg.com/vi/GET_THIS_STRING/default.jpg
It is always default.jpg so just change where I placed GET_THIS_STRING. Easy as pie.









