从Youtube官方频道获取视频

时间:2016-05-02 17:19:34

标签: java youtube-api

有一些Youtube官方频道,如音乐,游戏,新闻等。我试图获取这些频道的信息,就像它是一个正常频道,但它发送我的空响应。这可能是因为频道视频不归渠道所有,即使它们将其显示为"已上传的视频"。这是我的代码,与#34; normal"频道:( String ids表示每个视频逗号的ID分隔)

此方法提供频道视频的视频,并使用" normal"信道。

public static ArrayList<VideoYoutube> getVideos (String ids) throws IOException
{
    try
    {
        YouTube.Videos.List videos = youtube.videos().list("id,snippet,statistics");

        videos.setKey(API_KEY);
        //Setting all the video ids we want to get back
        videos.setId(ids);
        videos.setMaxResults(RETURN_NUMBER);
        //Setting all the fields we want to be called from the api. Its such an
        videos.setFields("items(id,snippet/publishedAt,snippet/title,snippet/description," +
                    "snippet/thumbnails/default/url,snippet/thumbnails/medium/url,snippet/thumbnails/high/url," +
                    "snippet/channelId,snippet/channelTitle,statistics/viewCount,statistics/likeCount,statistics/dislikeCount," +
                    "statistics/favoriteCount,statistics/commentCount)");
        VideoListResponse videoResponse = videos.execute();

        List<Video> videoResultList = videoResponse.getItems();
}

这是一种方法,可以从我想要的频道中检索视频ID。它为这个确切的频道提供了空值,但它是&#39;与&#34;正常&#34;合作信道。

public static String getChannelVideosIds(String channelId) throws IOException
{
    YouTube.Search.List search = youtube.search().list("id");
    //Define the search key
    search.setKey(API_KEY);
    search.setChannelId(channelId);
    //Give the type (video, playlist or channel)
    search.setType("video");
    //Giving the params we want to be returned comma separated(for example if we had choosed the snipped before, we could choose snipped fields like snipped/publishedAt)
    search.setFields("items(id)");
    //set the max return number
    search.setMaxResults(RETURN_NUMBER);
    //Execute the search query
    SearchListResponse searchResponse = search.execute();
    List<SearchResult> searchResultList = searchResponse.getItems();
    //check if the result is null
    return retrieveIds(searchResultList);
}

0 个答案:

没有答案