首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Java检索超过25个youtube评论

如何使用Java检索超过25个youtube评论
EN

Stack Overflow用户
提问于 2013-08-30 07:14:14
回答 1查看 1.2K关注 0票数 0
代码语言:javascript
复制
      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视频评论的代码。我可以使用这段代码检索大约25个注释,但是如何从视频中检索所有评论呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-30 10:28:42

我想是这样的:

代码语言:javascript
复制
// 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.
 }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18527048

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档