从 YouTube 获取视频标题 URL - Java

Fetching a video title from a YouTube URL - Java

我试图了解如何使用 Java 库在 YouTube API 上工作,并尝试做一些基本的事情,比如根据视频 ID 检索视频标题。但是,所有关于此的信息都指已弃用的 v2 API,如本 link (https://developers.google.com/youtube/2.0/developers_guide_protocol_video_entries?csw=1) 中所述,我无法在网上找到任何有关如何完成此操作的资源v3 API。如果有人也可以就使用 YouTube API 提出一些 books/references 的建议,我将不胜感激。

我对这个 API 很陌生。但是,this 不是您实现目标所需要的 API 的一部分吗?

snippet.title

我从来没有用过 Youtube 的API。 如有错误请指正

你要找的是.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");
  }
}
}

SearchResult中有getTitle()方法,请检查一次