YouTube Java 客户端 API:为什么 Video.getSnippet() 方法返回 null?

YouTube Java Client API: Why is the Video.getSnippet() method returning null?

我最近成功地调用了 YouTube API 来检索视频的观看次数,所以我决定也尝试获取标题,但我不明白出了什么问题。 此代码

YouTube.Videos.List list = youtube.videos().list(Arrays.asList("statistics"));
list.setId(Arrays.asList("video id here"));
String apiKey = "[redacted]";
list.setKey(apiKey);  
Video v = list.execute().getItems().get(0);
v.getStatistics().getViewCount()

returns 观看次数很好,但后来我尝试了这段代码:

    String title = "";
    title = v.getSnippet().getTitle();

我得到了一个 NullPointerException 因为 v.getSnippet() 正在返回 null...在调用 API 之前我需要在某处为某物分配某种价值吗为了让它实际获取应该在 VideoSnippet object?

中的数据

为方便起见,这里是 API 文档:https://googleapis.dev/java/google-api-services-youtube/latest/index.html

根据Videos.list API endpoint, to retrieve the snippet object associated to the video of which ID you're passing on to the endpoint, you have to include snippet within the names you pass on to the part请求参数的官方文档

使用生成的 Java 库时 Google Java API Client Services -- specifically that corresponding to YouTube Data API --,归结为将 Arrays.asList("statistics") 替换为 Arrays.asList("snippet", "statistics")