【问题标题】:How to retrieve more than 25 youtube comments using Java如何使用 Java 检索超过 25 条 youtube 评论
【发布时间】:2013-08-30 07:14:14
【问题描述】:
      YouTubeService service = new YouTubeService("MyApp");
      String videoEntryUrl = "http://gdata.youtube.com/feeds/api/videos/nU9dinwMyHo";
      VideoEntry videoEntry = service.getEntry(new URL(videoEntryUrl), VideoEntry.class);
      String commentUrl = videoEntry.getComments().getFeedLink().getHref();

      CommentFeed commentFeed = service.getFeed(new URL(commentUrl), CommentFeed.class);
      for(CommentEntry comment : commentFeed.getEntries()) {
        System.out.println(comment.getPlainTextContent());

这是我检索特定视频的 youtube cmets 的代码。 我可以使用此代码检索大约 25 个 cmets,但是如何从视频中检索所有 cmets?

【问题讨论】:

    标签: java youtube youtube-api


    【解决方案1】:

    我认为是这样的:

    // Get a video entry
    String str = "http://gdata.youtube.com/feeds/api/videos/" + videoId;
    YouTubeQuery youtubeQuery = new YouTubeQuery(new URL(str));
    String videoEntryUrl = youtubeQuery.getUrl().toString();
    VideoEntry videoEntry = service.getEntry(new URL(videoEntryUrl),VideoEntry.class);
    
    // Get the comments url for this video
    if (videoEntry.getComments() != null) {
        String commentUrl = videoEntry.getComments().getFeedLink().getHref();
        System.out.println(commentUrl);
    
        // Get the comment feed; use a new query
        YouTubeQuery youtubeQuery = new YouTubeQuery(new URL(commentUrl);
        youtubeQuery.setMaxResults(50);
    
    
        youtubeQuery.setStartIndex(1);
        String commentUrlFeed = youtubeQuery.getUrl().toString();
        CommentFeed commentFeed = service.getFeed(new URL(commentUrlFeed),CommentFeed.class);
        // The response should contain an url for the next feed, if any, already with an updated start-index.
    
        for (int i = 0; i < commentFeed.getEntries().size()
                && commentFeed.getEntries().get(i) != null; i++) {
    
            String author=commentFeed.getEntries().get(i).getAuthors().get(0).getUri().substring(41)
            String commentId=commentFeed.getEntries().get(i).getId().substring(47);
            String comment=commentFeed.getEntries().get(i).getPlainTextContent();
            }
        }
        // Loop thru next comment feed call, if more can be expected.
        // Use updated url from the response or set start-index = start-index + max-results.
     }
    

    【讨论】:

    • 这还能用吗? (与 G+ 集成有什么关系)
    • 直到今天我才查看我的消息。上面的代码使用的是已弃用的 api 版本 2。我不知道更改后,因为我自己不使用这个。
    猜你喜欢
    • 2013-10-22
    • 2014-05-14
    • 2014-05-28
    • 1970-01-01
    • 2021-04-22
    • 1970-01-01
    • 2016-11-22
    • 2016-11-19
    • 2015-09-26
    相关资源
    最近更新 更多