Google.Apis.YouTube.v3 编译频道统计失败 "The uri string is too long"

Google.Apis.YouTube.v3 compiling channel statistics fail "The uri string is too long"

我正在尝试为频道列表和第一页编译频道统计信息,但当我使用令牌调用下一页时,它给我一个错误,提示 URI 字符串太长。

我正在使用 .NET 核心 2.2 和 Google.Apis.YouTube.v2 V1.39.0.1572。我使用的代码非常简单:

var youtubeService = new YouTubeService(new BaseClientService.Initializer()
                {
                    ApiKey = Startup.Configuration["YTConfigurations:ApiKey"],
                    ApplicationName = this.GetType().ToString()
                });

                ChannelsResource.ListRequest channelsListRequest = youtubeService.Channels.List("snippet,statistics,brandingSettings,topicDetails");
                channelsListRequest.Id = string.Join(",", channelEntities.Select(v => v.YTChannelId));

                channelsListRequest.MaxResults = 50;

                do
                {
                    pageCounter++;
                    channelListResponse = channelsListRequest.Execute();//here is the error after page 1

                    foreach (var listResult in channelListResponse.Items)
                    {
                        channelEntity = channelEntities.FirstOrDefault(v => v.YTChannelId == listResult.Id);
                        channelEntity = Mapper.Map(listResult, channelEntity);   
                        _repository.UpdateChannel(channelEntity);
                    }

                    if (channelListResponse.NextPageToken != null)
                    {
                        channelsListRequest.PageToken = channelListResponse.NextPageToken;
                    }
                } while (channelListResponse.Items.Count == 50 && channelListResponse.NextPageToken != null);

当我执行这个时,我得到的是:

System.UriFormatException: Invalid URI: The Uri string is too long.
   at System.UriHelper.EscapeString(String input, Int32 start, Int32 end, Char[] dest, Int32& destPos, Boolean isUriString, Char force1, Char force2, Char rsvd)
   at System.Uri.EscapeDataString(String stringToEscape)
   at Google.Apis.Requests.RequestBuilder.<>c.<BuildUri>b__25_0(KeyValuePair`2 x) in C:\Apiary19-05-01.11-08-18\Src\Support\Google.Apis.Core\Requests\RequestBuilder.cs:line 108
   at System.Linq.Enumerable.SelectListIterator`2.ToArray()
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Google.Apis.Requests.RequestBuilder.BuildUri() in C:\Apiary19-05-01.11-08-18\Src\Support\Google.Apis.Core\Requests\RequestBuilder.cs:line 107
   at Google.Apis.Requests.RequestBuilder.CreateRequest() in C:\Apiary19-05-01.11-08-18\Src\Support\Google.Apis.Core\Requests\RequestBuilder.cs:line 332
   at Google.Apis.Requests.ClientServiceRequest`1.CreateRequest(Nullable`1 overrideGZipEnabled) in C:\Apiary19-05-01.11-08-18\Src\Support\Google.Apis\Requests\ClientServiceRequest.cs:line 257
   at Google.Apis.Requests.ClientServiceRequest`1.ExecuteUnparsedAsync(CancellationToken cancellationToken) in C:\Apiary19-05-01.11-08-18\Src\Support\Google.Apis\Requests\ClientServiceRequest.cs:line 229
   at Google.Apis.Requests.ClientServiceRequest`1.Execute() in C:\Apiary19-05-01.11-08-18\Src\Support\Google.Apis\Requests\ClientServiceRequest.cs:line 167
   at ChannelHarvester.Controllers.ChannelHarvester.extractStats(ICollection`1 channelEntities) in C:\Guayaba Projects\YT_ChannelHarvester\ChannelHarvester\Controllers\ChannelHarvester.cs:line 106

我是不是做错了什么?如果有什么我可以解决的,请告诉我。 谢谢!

不好意思,打扰了大家。我找到了它是什么,在下面的代码中我以为我只加入了 50 个 ID,但显然在某些情况下我发送了很多。

channelsListRequest.Id = string.Join(",", channelEntities.Select(v => v.YTChannelId));

所以我想我们可以关闭这个