Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

Youtube V3 API - Retrieving content details part of channel resource results in 'operation is not valid due to the current state of the object'

$
0
0

I'm using the Youtube V3 API nuget package for C#, and I am experiencing a JSON issue when Retrieving the contentDetails part of the channel resource.

Is there currently a bug in the API causing server side 500 errors?

Here is my code for the implementation.The error is happening when I call this line of code:

var channelsListResponse = await channelsListRequest.ExecuteAsync();

public async Task<IEnumerable<Snippet>> GetAllAsync()    {        var videoList = new List<Snippet>();        // Create the service        var service = new YouTubeService(new BaseClientService.Initializer        {            ApplicationName = this.GetType().ToString(),            ApiKey = _apiKey        });        var channelsListRequest = service.Channels.List("contentDetails");        channelsListRequest.Mine = true;        // Retrieve the contentDetails part of the channel resource for the authenticated user's channel.        var channelsListResponse = await channelsListRequest.ExecuteAsync();        foreach (var channel in channelsListResponse.Items)        {            // From the API response, extract the playlist ID that identifies the list            // of videos uploaded to the authenticated user's channel.            var uploadsListId = channel.ContentDetails.RelatedPlaylists.Uploads;            var nextPageToken = "";            while (nextPageToken != null)            {                var playlistItemsListRequest = service.PlaylistItems.List("snippet");                playlistItemsListRequest.PlaylistId = uploadsListId;                playlistItemsListRequest.MaxResults = 50;                playlistItemsListRequest.PageToken = nextPageToken;                // Retrieve the list of videos uploaded to the authenticated user's channel.                var playlistItemsListResponse = await playlistItemsListRequest.ExecuteAsync();                foreach (var playlistItem in playlistItemsListResponse.Items)                {                    // Print information about each video.                    // Console.WriteLine("{0} ({1})", playlistItem.Snippet.Title, playlistItem.Snippet.ResourceId.VideoId);                    videoList.Add(new Snippet()                    {                        Title = playlistItem.Snippet.Title                    });                }                nextPageToken = playlistItemsListResponse.NextPageToken;            }        }        return videoList;    }

Here is the result of running the method using a controller and postman...

I am using a snippet I found on the Youtube API documentation for samples.

https://developers.google.com/youtube/v3/code_samples/dotnet#retrieve_my_uploads

System.InvalidOperationException: Operation is not valid due to the current state of the object.   at System.Text.Json.Serialization.JsonConverter`1.WriteNumberWithCustomHandling(Utf8JsonWriter writer, T value, JsonNumberHandling handling)   at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer)   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack& state)   at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)   at System.Text.Json.Serialization.JsonConverter`1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)   at System.Text.Json.Serialization.JsonConverter`1.WriteCoreAsObject(Utf8JsonWriter writer, Object value, JsonSerializerOptions options, WriteStack& state)   at System.Text.Json.JsonSerializer.WriteCore[TValue](JsonConverter jsonConverter, Utf8JsonWriter writer, TValue& value, JsonSerializerOptions options, WriteStack& state)   at System.Text.Json.JsonSerializer.WriteStreamAsync[TValue](Stream utf8Json, TValue value, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken)   at System.Text.Json.JsonSerializer.WriteStreamAsync[TValue](Stream utf8Json, TValue value, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken)   at System.Text.Json.JsonSerializer.WriteStreamAsync[TValue](Stream utf8Json, TValue value, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken)   at Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()--- End of stack trace from previous location ---   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)HEADERS=======Accept: */*Connection: keep-aliveHost: localhost:7072User-Agent: PostmanRuntime/7.28.4Accept-Encoding: gzip, deflate, brPostman-Token: 809fd2c7-2fed-4c67-a01a-151d35b45241

Any help on this would be appreciated..


Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>