如何使用java检索youtube搜索结果及其视频ID?

时间:2012-07-17 18:51:21

标签: java youtube

我知道如果给出视频ID,如何检索所有统计信息。 但如果我必须根据查询标题检索搜索结果的视频ID(20),那么我无法做到。 任何人都可以帮助我使用 JAVA API 来处理它。

非常感谢。

1 个答案:

答案 0 :(得分:4)

您是否搜索过Google文档? 他们的指南正是您所寻找的:YouTube API - Searching for Videos

它甚至给你一个例子:

YouTubeQuery query = new YouTubeQuery(new URL("http://gdata.youtube.com/feeds/api/videos"));
// order results by the number of views (most viewed first)
query.setOrderBy(YouTubeQuery.OrderBy.VIEW_COUNT);

// search for puppies and include restricted content in the search results
query.setFullTextQuery("puppy");
query.setSafeSearch(YouTubeQuery.SafeSearch.NONE);

VideoFeed videoFeed = service.query(query, VideoFeed.class);

从返回的VideoFeed中,您可以轻松获取视频ID。

for(VideoEntry videoEntry : videoFeed.getEntries() ) {
     YouTubeMediaGroup mediaGroup = videoEntry.getMediaGroup();
     mediaGroup.getVideoId(); // the video ID
}