A bunch of SO answers shows that the YouTube API v3 doesn't yet provide a trivial way to get a YouTube channel by its handle. A workaround is to perform a search with the handle as a search term :
- Answer of How to get Youtube channel details using Youtube data API if channel has custom url
- Answer of YouTube Data API Get Channel by Handle
- Answer of How to map youtube handles to channel IDs
- Answer of How can I get YouTube channel ID using channel name URL?
Then, to retrieve only the first result being a channel, this piece of code can be used:
SearchResource.ListRequest SRLR = this.YouTubeService.Search.List("snippet");SRLR.Q = Handle;// SRLR.SafeSearch = SearchResource.ListRequest.SafeSearchEnum.None;SRLR.MaxResults = 1;// SR contains the first result that *should* be the searched channel// otherwise an exception is thrown SearchResult SR = SRLR.Execute().Items.Where(x => x.Id.Kind == "youtube#channel").Single();Then, this result can be checked by retrieving the channel by its Id and comparing the search term with the actual channel handle.
ChannelsResource.ListRequest CRLR = this.YouTubeService.Channels.List(part);CRLR.Id = SR.Snippet.ChannelId;Channel Channel = CRLR.Execute().Items.Single();if (Channel.Snippet.CustomUrl != Handle) throw new System.Exception($"No channel with handle \"{Handle}\"");Finally, it is possible to process the channel itself.
This works very well with some handles like @aha or @Queen.
However, the search doesn't return a channel for the handle @lachaiseproductions1654, although it appears from a YouTube Web search.
Yet this channel can be reached by its id (UCDSqPuB6YKO4E5FjKP1R23Q). Why did I miss?