Search code examples
c#youtube-data-apiplaylist

get all playlist of an user from YouTube. working in api explorer but not in c#


I wanna get all playlists of a channel all settings works on API explorer but when I try it in the client it not working other things of youtube data api3 like channel and playlistitems working, my problem is just with playlist.list

      UserCredential credential;
  using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
  {
    credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
        GoogleClientSecrets.Load(stream).Secrets,
        // This OAuth 2.0 access scope allows for full read/write access to the
        // authenticated user's account.
        new[] { YouTubeService.Scope.Youtube },
        "user",
        CancellationToken.None,
        new FileDataStore(this.GetType().ToString())
    );
  }

  var youtubeService = new YouTubeService(new BaseClientService.Initializer()
  {
    HttpClientInitializer = credential,
    ApplicationName = this.GetType().ToString()
  });
        var channelVids = youtubeService.Playlists.List("snippet");
        channelVids.Id = "UCIabPXjvT5BVTxRDPCBBOOQ";
        //channelVids.Fields = "items(id,snippet(description,publishedAt,thumbnails/default/url,title)),nextPageToken";
        channelVids.MaxResults = 25;
        var results = await channelVids.ExecuteAsync();
        Console.WriteLine(results.Items.Count + " lists");

Solution

  • I found my solution it was just a typo

    channelVids.Id = "UCIabPXjvT5BVTxRDPCBBOOQ";
    

    to

    channelVids.ChannelId = "UCIabPXjvT5BVTxRDPCBBOOQ";