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

时间:2015-02-06 21:28:24

标签: android youtube-api android-youtube-api

我正在尝试在官方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;
    }
}

它完美无缺..但我不知道如何在我的主要活动中显示要观看的内容..我发现this但它只适用于版本2 ..任何想法?

1 个答案:

答案 0 :(得分:3)

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

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