C#Youtube使用高级搜索搜索Api

时间:2016-11-24 07:33:15

标签: c# youtube

我想在youtube上学习搜索API。我使用了示例项目,我想改进它。示例顺序,视频时长



 searchListRequest.VideoDuration = SearchResource.ListRequest.VideoDurationEnum.Medium;
 



 这个给予 类型为' System.Reflection.TargetInvocationException'的未处理异常发生在mscorlib.dll

附加信息:调用目标引发了异常。

这是错误的。我将如何使用VideoDuration

我试过



searchListRequest.VideoDuration = "Medium";




这给了 错误CS0029无法隐式转换类型'字符串'到了Google.Apis.YouTube.v3.SearchResource.ListRequest.OrderEnum?'

我的所有代码是;



   var youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                ApiKey = "xxxx",
                ApplicationName = this.GetType().ToString()
            });

            var searchListRequest = youtubeService.Search.List("snippet");
            searchListRequest.Q = "Google"; // Replace with your search term.
            searchListRequest.MaxResults = 50;
            switch (videoduration.SelectedIndex) //Combobox
            {
                case 0 :
                    searchListRequest.VideoDuration = SearchResource.ListRequest.VideoDurationEnum.Any;
                    break;
                case 1:
                    searchListRequest.VideoDuration = SearchResource.ListRequest.VideoDurationEnum.Short__;
                    break;
                case 2:
                    searchListRequest.VideoDuration = SearchResource.ListRequest.VideoDurationEnum.Medium;
                    break;
                case 3:
                    searchListRequest.VideoDuration = SearchResource.ListRequest.VideoDurationEnum.Long__;
                    break;
            }

    

            // Call the search.list method to retrieve results matching the specified query term.
            var searchListResponse = await searchListRequest.ExecuteAsync();

            List<string> videos = new List<string>();
            List<string> channels = new List<string>();
            List<string> playlists = new List<string>();

            // Add each result to the appropriate list, and then display the lists of
            // matching videos, channels, and playlists.
            foreach (var searchResult in searchListResponse.Items)
            {
                richTextBox1.AppendText(searchResult.Snippet.Title + Environment.NewLine);
                richTextBox1.AppendText("https://youtu.be/"+ searchResult.Id.VideoId + Environment.NewLine);
                richTextBox1.AppendText(Environment.NewLine);

            }
&#13;
&#13;
&#13;

0 个答案:

没有答案