Reputation: 157
I was trying to learn about how to work with the YouTube API using Java libraries, and was trying to do something basic like retrieving a video title given the video ID. However, all the information on this refers to the deprecated v2 API as explained in this link (https://developers.google.com/youtube/2.0/developers_guide_protocol_video_entries?csw=1) and I have not been able to find any sources online on how to accomplish this for the v3 API. If anyone could suggest some books/references on working with the YouTube API as well, I would be extremely grateful.
Upvotes: 1
Views: 3007
Reputation: 28
There is a method called getTitle() in SearchResult, please check that once.
Upvotes: -1
Reputation: 3549
What you are looking for is .getTitle()
There are a few examples at https://developers.google.com/youtube/v3/code_samples/java?hl=es
for example:
private static void prettyPrint(Iterator<SearchResult> iteratorSearchResults, String query) {
System.out.println("\n=============================================================");
System.out.println(
" First " + NUMBER_OF_VIDEOS_RETURNED + " videos for search on \"" + query + "\".");
System.out.println("=============================================================\n");
if (!iteratorSearchResults.hasNext()) {
System.out.println(" There aren't any results for your query.");
}
while (iteratorSearchResults.hasNext()) {
SearchResult singleVideo = iteratorSearchResults.next();
ResourceId rId = singleVideo.getId();
// Double checks the kind is video.
if (rId.getKind().equals("youtube#video")) {
Thumbnail thumbnail = singleVideo.getSnippet().getThumbnails().get("default");
System.out.println(" Video Id" + rId.getVideoId());
System.out.println(" Title: " + singleVideo.getSnippet().getTitle());
System.out.println(" Thumbnail: " + thumbnail.getUrl());
System.out.println("\n-------------------------------------------------------------\n");
}
}
}
Upvotes: 2