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

Google Youtube API Search doesn't retrieve all videos in the channel

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

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

请求不会检索所有视频,它 returns 总共 9 个中只有 7 个。 所有视频都具有相同的配置。丢失的视频总是一样的。

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

有人可以帮助我吗?

提前致谢

弗朗切斯科

"How do I obtain a list of all videos in a channel using the YouTube Data API v3?"here的答案可能就是您所需要的。请特别查看答案中链接的视频。

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

尝试这种两步法:

  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}

试试这个

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;
    }

}