检索YouTube API V3 Android中的热门视频



我正在尝试获取Youtube官方应用程序上最受欢迎的视频或观看内容,以便在使用Youtube api v3的Youtube应用程序中显示。

我使用以下代码搜索具有特定关键字的视频。。

public List<VideoItem> search(String keywords) {
    query.setQ(keywords);
    try {
        SearchListResponse response = query.execute();
        List<SearchResult> results = response.getItems();
        List<VideoItem> items = new ArrayList<VideoItem>();
        for (SearchResult result : results) {
            String videoURL = "http://www.youtube.com/watch?v=" + result.getId().getVideoId();
            VideoItem item = new VideoItem(result.getSnippet().getTitle(),
                    result.getSnippet().getDescription(), result
                            .getSnippet().getThumbnails().getDefault()
                            .getUrl(), result.getId().getVideoId(), videoURL);
            items.add(item);
        }
        return items;
    } catch (IOException e) {
        Log.d("YC", "Could not search: " + e);
        return null;
    }
}

而且效果非常好。。但我不知道如何在我的主要活动中显示"观看内容"。。我找到了这个,但它只在版本2中有效。有什么想法吗?

使用开发者API密钥为YouTube API V3使用以下内容检索YouTube API V3:中的热门视频

https://www.googleapis.com/youtube/v3/videos?chart=mostPopular&key={YOUR_API_KEY}&part=snippet&maxResults=4

最新更新