有关 google-api-java-client 的帮助

发布于 2024-10-02 10:15:35 字数 1113 浏览 1 评论 0原文

我正在尝试解析 YouTube 视频源,并为每个视频打印其缩略图列表。 我已经尝试过类似的方法:

 public static class VideoFeed {
    @Key List<Video> items;
  }

  public static class Video {
    @Key String title;
    @Key String description;
    @Key DateTime uploaded;
    @Key Player player;
    @Key Thumbnail thumbnail;
  }

  public static class Player {
    @Key("default") String defaultUrl;
  }



  public static class Thumbnail{

    List<Thumb> items = new ArrayList<Thumb>();
  }

  public static class Thumb extends GenericJson{
      @Key("default") String defaultUrl;
      @Key Integer height;
      @Key Integer width;
      @Key String time;

  }

并打印它

for (Video video : feed.items) {
  System.out.println();
  System.out.println("Video title: " + video.title);
  System.out.println("Uploaded: " + video.uploaded);
  System.out.println("URL: " + video.player.defaultUrl);

  Thumbnail thumbnails = video.thumbnail;
  for (Thumb thumb : thumbnails.items){

      System.out.println("Thumbnail: "+thumb.defaultUrl);
  }

}

但缩略图没有被打印。

有什么问题吗?

I'm trying to parse a youtube video feed, and for each video print the list of its thumbnails.
I've tried something like that:

 public static class VideoFeed {
    @Key List<Video> items;
  }

  public static class Video {
    @Key String title;
    @Key String description;
    @Key DateTime uploaded;
    @Key Player player;
    @Key Thumbnail thumbnail;
  }

  public static class Player {
    @Key("default") String defaultUrl;
  }



  public static class Thumbnail{

    List<Thumb> items = new ArrayList<Thumb>();
  }

  public static class Thumb extends GenericJson{
      @Key("default") String defaultUrl;
      @Key Integer height;
      @Key Integer width;
      @Key String time;

  }

and print it

for (Video video : feed.items) {
  System.out.println();
  System.out.println("Video title: " + video.title);
  System.out.println("Uploaded: " + video.uploaded);
  System.out.println("URL: " + video.player.defaultUrl);

  Thumbnail thumbnails = video.thumbnail;
  for (Thumb thumb : thumbnails.items){

      System.out.println("Thumbnail: "+thumb.defaultUrl);
  }

}

But the thumbnails don't get printed.

What's the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花开浅夏 2024-10-09 10:15:35

是因为您缺少 Thumbnail.items 上的 @Key 注释吗?

Is it because you are missing the @Key annotation on the Thumbnail.items?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文