我试图了解如何使用Java库处理YouTube API,并试图做一些基本的事情,例如在给定视频ID的情况下检索视频标题。但是,有关这方面的所有信息都是指已弃用的v2 API,如此链接(https://developers.google.com/youtube/2.0/developers_guide_protocol_video_entries?csw=1)中所述,我无法在线找到有关如何为v3 API实现此目的的任何来源。如果有人可以推荐一些有关使用YouTube API的书籍/参考资料,我将非常感激。
答案 0 :(得分:2)
您正在寻找的是.getTitle()
https://developers.google.com/youtube/v3/code_samples/java?hl=es
有几个例子例如:
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");
}
}
}
答案 1 :(得分:0)
答案 2 :(得分:-1)
在SearchResult中有一个名为getTitle()的方法,请检查一次。