尝试从youtube检索用户评论。代码如下:
String videoId = "3u1fu6f8Hto";
String str = "http://gdata.youtube.com/feeds/api/videos/" + videoId + "/comments";
YouTubeQuery youtubeQuery = new YouTubeQuery(new URL(str));
youtubeQuery.setMaxResults(50);
youtubeQuery.setStartIndex(1);
String videoEntryUrl = youtubeQuery.getUrl().toString();
VideoEntry videoEntry = service.getEntry(new URL(videoEntryUrl), VideoEntry.class);
String myUrl = youtubeQuery.getUrl().toString(); // only another name
CommentFeed commentFeed = service.getFeed(new URL(myUrl), CommentFeed.class); // Feed response
代码显示不兼容的类型:URL无法转换为字符串
答案 0 :(得分:1)
要从youtube检索评论,请尝试执行以下操作:
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());
}
这是一个方便的链接:https://developers.google.com/youtube/2.0/developers_guide_java#Comments