Youtube api 谷歌Youtube API搜索没有';无法检索频道中的所有视频

Youtube api 谷歌Youtube API搜索没有';无法检索频道中的所有视频,youtube-api,Youtube Api,我必须用Youtube API检索我频道的所有视频。 所有视频都发布在Youtube上,我可以正确地看到它们 我试图直接从此页面提出请求: 这是一个示例请求: 获取http://www.googleapis.com/youtube/v3/search?part=snippet&channelId=myChannelID&maxResults=50&key={YOUR_API_key} 请求不会检索所有视频,它只返回9个视频中的7个。 所有视频都具有相同的配置。丢失的视频总是一样的 如果我使用视频

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

我试图直接从此页面提出请求: 这是一个示例请求: 获取http://www.googleapis.com/youtube/v3/search?part=snippet&channelId=myChannelID&maxResults=50&key={YOUR_API_key}

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

如果我使用视频API传递搜索响应中排除的其中一个视频的ID,它将返回正确的响应,并且它正确地属于我的频道:

有人能帮我吗

先谢谢你

Francesco

您可能需要回答“如何使用YouTube数据API v3获取频道中所有视频的列表?”。请特别注意答案中链接到的视频

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

尝试以下两步方法:

  • 使用channels.list API调用获取频道上传播放列表的ID:
    Gethttps://www.googleapis.com/youtube/v3/channels?part=contentDetails&id={YOUR_CHANNEL_ID}&key={YOUR_API_key}
  • 使用playlitems从上传播放列表中获取视频。列表调用:
    Gethttps://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;
        }
    
    }
    
    异步静态任务GetVideosList(配置,字符串searchText=“”,int-maxResult=20)
    {
    列表视频=新建列表();
    使用(var youtubeService=new youtubeService(new BaseClientService.Initializer())
    {
    ApiKey=configurations.ApiKey
    }))
    {
    var searchListRequest=youtubeService.Search.List(“代码段”);
    searchListRequest.Q=searchText;
    searchListRequest.MaxResults=maxResult;
    searchListRequest.ChannelId=configurations.ChannelId;
    searchListRequest.Type=“视频”;
    searchListRequest.Order=SearchResource.ListRequest.OrderEnum.Date;//相关性;
    var searchListResponse=等待searchListRequest.ExecuteAsync();
    foreach(searchListResponse.Items中的var responseVideo)
    {
    videos.Add(新的YouTubeVideo()
    {
    Id=响应视频Id.Id.VideoId,
    Description=responseVideo.Snippet.Description,
    Title=responseVideo.Snippet.Title,
    Picture=GetMainImg(responseVideo.Snippet.Thumbnails),
    thumboil=GetThumbnailImg(responseVideo.Snippet.thumboils)
    });
    }
    返回视频;
    }
    }
    
    您的频道ID是什么?这样我们可以运行与您相同的测试。谢谢,这是我解决问题的第二个解决方案。即使我不明白为什么搜索API不能正常工作。@mmirus playlitems.list()从某个上传ID开始工作,抛出404表示未找到其他播放列表。search.list()适用于所有视频,但会返回旧视频。@DevsYakamoz:您是否找到了使用搜索列出所有视频(特别是按时间顺序)的方法?@mmirus在PlayItems端点中如何使用一些日期范围参数,如publishAfter/publishedBefore。我试过了,但没有成功,所以我如何获取一个频道的所有视频。这也解决了我在搜索频道ID和日期订单的视频时遇到的问题。结果不可靠(随机丢失最新视频)。而每次通话获取频道列表和播放列表项目的配额成本仅为1。如今,当每日配额减少到10.000时,哪一点很重要?此C#代码与OP的问题有什么关系?IDE是类似于类型和搜索文本的配置