Youtube API V3搜索文本并获取ID,视图和Snippet图片网址之类的特定详细信息

问题描述 投票:0回答:1

我正在尝试获取YouTube视频的特定项目,包括ID,snippet.thumbnails。(key).url,statistics.viewCount

我可以通过在字段中提及来查询特定于ID的信息,但不确定如何在其中添加我感兴趣的其他字段。 https://developers.google.com/youtube/v3/docs/videos#resource

                string youtubeApiKey = DataConstants.YoutubeApiKey;
                YouTubeService youtubeService = new YouTubeService(new BaseClientService.Initializer()
                {
                    ApiKey = youtubeApiKey,
                    ApplicationName = this.GetType().ToString()
                });

                var searchListRequest = youtubeService.Search.List("snippet");
                searchListRequest.Q = searchText;
                searchListRequest.MaxResults = 1; // 5
                searchListRequest.Type = "video";
                searchListRequest.VideoSyndicated = SearchResource.ListRequest.VideoSyndicatedEnum.True__;
                searchListRequest.VideoEmbeddable = SearchResource.ListRequest.VideoEmbeddableEnum.True__;

                // *** Here I need to mention the additional fields *** 
                searchListRequest.Fields = "items(id)";
                // items(id, statistics.viewCount) doesn't work                     


                var searchListResponse = await searchListRequest.ExecuteAsync();
                foreach (var searchResult in searchListResponse.Items)
                {
                        if (searchResult.Id.Kind == "youtube#video")
                        {
                            return searchResult.Id.VideoId;
                        }
                        return null;
                 }
                }

searchListRequest.Fields =“ items(id)”有效,但添加其他字段将无效:items(id,statistics.viewCount)。

任何想法如何正确传递这些字段

编辑:如IkarosKun所述,搜索api不支持统计信息部分。https://developers.google.com/youtube/v3/determine_quota_cost

c# youtube-data-api
1个回答
0
投票

您使用的方法是searchListRequest,如文档所述,搜索api仅重新调整snippet零件数据,如果要获取statistics零件数据,则只能通过具有的视频ID获取视频数据得到。

© www.soinside.com 2019 - 2024. All rights reserved.