Google Youtube API搜索不会检索频道中的所有视频

时间:2015-05-12 13:02:47

标签: youtube-api

我必须使用Youtube API检索我频道的所有视频。 所有视频都在Youtube上发布,我可以正确看到它们。

我尝试直接从此页面发出请求: https://developers.google.com/youtube/v3/docs/search/list 这是示例请求: 获取http:http://www.googleapis.com/youtube/v3/search?part = snippet& channelId = myChannelID& maxResults = 50& key = {YOUR_API_KEY}

请求不会检索所有视频,它只返回总数为9的7。 所有视频都具有相同的配置。缺少的视频总是一样的。

如果我使用视频API传递从搜索响应中排除的其中一个视频的ID,则会返回正确的响应并且它正确属于我的频道: https://developers.google.com/youtube/v3/docs/videos/list#try-it

有人可以帮助我吗?

提前谢谢

弗朗西斯

2 个答案:

答案 0 :(得分:4)

答案"如何使用YouTube Data API v3获取频道中所有视频的列表?" here可能就是您所需要的。请特别关注答案中链接的视频。

总而言之,要从频道获取所有上传内容,您需要使用该播放列表ID上的playlistItems.list从该频道的上传播放列表中获取项目,而不是在频道ID上调用search.list

尝试这两步法:

  1. 使用channels.list API调用获取您频道的上传播放列表的ID:GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id={YOUR_CHANNEL_ID}&key={YOUR_API_KEY}
  2. 使用playlistItems.list调用从上传播放列表中获取视频:GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=3&playlistId={YOUR_PLAYLIST_ID}&key={YOUR_API_KEY}

答案 1 :(得分:0)

尝试

async static Task<IEnumerable<YouTubeVideo>> GetVideosList(Configurations configurations, string searchText = "", int maxResult = 20)
{
    List<YouTubeVideo> videos = new List<YouTubeVideo>();

    using (var youtubeService = new YouTubeService(new BaseClientService.Initializer()
    {
        ApiKey = configurations.ApiKey
    }))
    {
        var searchListRequest = youtubeService.Search.List("snippet");
        searchListRequest.Q = searchText;
        searchListRequest.MaxResults = maxResult;
        searchListRequest.ChannelId = configurations.ChannelId;
        searchListRequest.Type = "video";
        searchListRequest.Order = SearchResource.ListRequest.OrderEnum.Date;// Relevance;


        var searchListResponse = await searchListRequest.ExecuteAsync();


        foreach (var responseVideo in searchListResponse.Items)
        {
            videos.Add(new YouTubeVideo()
            {
                Id = responseVideo.Id.VideoId,
                Description = responseVideo.Snippet.Description,
                Title = responseVideo.Snippet.Title,
                Picture = GetMainImg(responseVideo.Snippet.Thumbnails),
                Thumbnail = GetThumbnailImg(responseVideo.Snippet.Thumbnails)
            });
        }

        return videos;
    }

}
相关问题