我可以';不要通过频道在youtube上获取视频.为什么?

本文关键字:youtube 获取 视频 为什么 频道 我可以 | 更新日期: 2023-09-27 17:53:11

https://www.youtube.com/channel/UC-9-kyTW8ZkZNDHQJ6FgpwQ

public async System.Threading.Tasks.Task<List<ViewModel.YoutubeVideo>> GetYoutubeMusic()
    {
        var youtubeService = new YouTubeService(new BaseClientService.Initializer()
        {
            ApiKey = "....",
            ApplicationName = this.GetType().ToString()
        });

        var searchListRequest = youtubeService.Channels.List("snippet");
        searchListRequest.Id= "UC-9-kyTW8ZkZNDHQJ6FgpwQ";
        searchListRequest.MaxResults = 25;

        //Call the search.list method to retrieve results...
        var searchListResponse = await searchListRequest.ExecuteAsync();
        List<ViewModel.YoutubeVideo> arrays = new List<ViewModel.YoutubeVideo>();
        foreach (var searchResult in searchListResponse.Items)
        {
            product = new ViewModel.YoutubeVideo();
            product.id = searchResult.Id;
            product.Name = searchResult.Snippet.Title;
            product.Thumb100Uri = searchResult.Snippet.Thumbnails.Default.Url;
            product.Thumb200Uri = searchResult.Snippet.Thumbnails.Medium.Url;
            arrays.Add(product);
        }
        return arrays;
    }

只是从这个频道获取信息,但没有视频。。。我不明白。请解决它。

我可以';不要通过频道在youtube上获取视频.为什么?

因为您没有调用search.list方法。您正在代码中调用channels.list方法。

但如果你已经有了频道的id,你应该只检索该频道上传的视频。