--- title: "Yt::Channel" h2: "Channels" ---

Yt::Channel represents a YouTube channel. Initialize using its YouTube ID:

{% include doc.html instance="Channel#initialize" %}{% include example.html object='channel = Yt::Channel' method='new' params=' id: "UCwCnUcLcb9-eSrHa_RQGkQQ"' %}
{% include example.html result='#<Yt::Channel @id=UCwCnUcLcb9-eSrHa_RQGkQQ>' %}
{% include doc.html instance="Channel#canonical_url" %}{% include example.html object='channel' method='canonical_url' %}
{% include example.html result='"https://www.youtube.com/channel/UCwCnUcLcb9-eSrHa_RQGkQQ"' %}

Authentication

Most methods of Yt::Channel retrieve public data from YouTube (e.g.: fetch a channel’s title).
To use these methods (marked with   below), you only need to generate an API key and configure:

{% highlight ruby %} Yt.configuration.api_key = "" ## use your API key channel = Yt::Channel.new id: 'UCwCnUcLcb9-eSrHa_RQGkQQ' ## use any channel ID channel.title # => "Yt Test" {% endhighlight %}

Other methods acts on behalf of YouTube accounts (e.g.: subscribe to a channel, delete playlists).
To use these methods (marked with   below), you need to get an API Client ID/Secret from Google, then obtain a refresh token from the account you want to act as, and finally configure the values:

{% highlight ruby %} Yt.configuration.client_id = "" ## replace with your client ID Yt.configuration.client_secret = "" ## replace with your client secret Yt.configuration.refresh_token = "" ## use the account’s refresh token channel = Yt::Channel.mine # => # {% endhighlight %}

List of Yt::Channel data methods

{% include dt.html title="Channel’s snippet" label="success" auth="any authentication works" %}
{% include doc.html instance="Channel#id" %}{% include example.html object='channel' method='id' result='"UCwCnUcLcb9-eSrHa_RQGkQQ"' %}
{% include doc.html instance="Channel#title" %}{% include example.html object='channel' method='title' result='"Yt Test"' %}
{% include doc.html instance="Channel#description" %}{% include example.html object='channel' method='description' result='"A test channel."' %}
{% include doc.html instance="Channel#custom_url" %}{% include example.html object='channel' method='custom_url' result='"yt-test"' %}
{% include doc.html instance="Channel#vanity_url" %}{% include example.html object='channel' method='vanity_url' result='"https://www.youtube.com/yt-test"' %}
{% include doc.html instance="Channel#published_at" %}{% include example.html object='channel' method='published_at' result='2014-05-02 20:12:57 UTC' %}
{% include doc.html instance="Channel#thumbnail_url" %}{% include example.html object='channel' method='thumbnail_url' result='"https://yt3.ggpht.com/-KMnbKDBl60w/photo.jpg"' %}
{% include dt.html title="Channel’s status" label="success" auth="any authentication works" %}
{% include doc.html instance="Channel#privacy_status" %}{% include example.html object='channel' method='privacy_status' result='"public"' %}
{% include doc.html instance="Channel#is_linked" %}{% include example.html object='channel' method='is_linked' result='true' %}
{% include doc.html instance="Channel#long_uploads_status" %}{% include example.html object='channel' method='long_uploads_status' result='"longUploadsUnspecified"' %}
{% include dt.html title="Channel’s statistics" label="success" auth="any authentication works" %}
{% include doc.html instance="Channel#view_count" %}{% include example.html object='channel' method='view_count' result='123' %}
{% include doc.html instance="Channel#comment_count" %}{% include example.html object='channel' method='comment_count' result='93' %}
{% include doc.html instance="Channel#subscriber_count" %}{% include example.html object='channel' method='subscriber_count' result='42' %}
{% include doc.html instance="Channel#hidden_subscriber_count" %}{% include example.html object='channel' method='hidden_subscriber_count' result='false' %}
{% include doc.html instance="Channel#video_count" %}{% include example.html object='channel' method='video_count' result='62' %}
{% include dt.html title="Channel’s branding settings" label="success" auth="any authentication works" %}
{% include doc.html instance="Channel#banner_image_url" %}{% include example.html object='channel' method='banner_image_url' result='"https://yt3.ggpht.com/9dh4rj-k-no"' %}
{% include doc.html instance="Channel#keywords" %}{% include example.html object='channel' method='keywords' result='["Some", "tag"]' %}
{% include doc.html instance="Channel#unsubscribed_trailer" %}{% include example.html object='channel' method='unsubscribed_trailer' result='"gknzFj_0vvY"' %}
{% include doc.html instance="Channel#featured_channels_title" %}{% include example.html object='channel' method='featured_channels_title' result='"Featured channels"' %}
{% include doc.html instance="Channel#featured_channels_urls" %}{% include example.html object='channel' method='featured_channels_urls' result='["UCxO1tY8h1AhOz0T4ENwmpow"]' %}
{% include dt.html title="Channel’s content details" label="warning" auth="must authenticate as the channel’s account" %}
{% include doc.html instance="Channel#related_playlists" %}{% include example.html object='channel' method='related_playlists' result='{"likes"=>"LLwCncb9-e", "watchHistory"=>"HL"}' %}
{% include doc.html instance="Channel#like_playlists" %}{% include example.html object='channel' method='like_playlists' result='#<Yt::Relation [#<Yt::Playlist @id=LLWCncb...>]>' %}

To limit the number of HTTP requests, use select to specify which parts of the channel’s data to load:

{% include example.html object='slow = channel' result='without select: 2 HTTP requests' %}
{% include example.html object='slow' method='title' result='one HTTP request to fetch the channel’s snippet' %}
{% include example.html object='slow' method='privacy_status' result='another HTTP request to fetch the channel’s status' %}

{% include doc.html instance="Channel#select" %}{% include example.html object='fast = channel' method='select' params=' :snippet, :status' result='with select: 1 HTTP request' %}
{% include example.html object='fast' method='title' result='one HTTP request to fetch both the channel’s snippet and status' %}
{% include example.html object='fast' method='privacy_status' result='no extra HTTP requests' %}
{% include dt.html title="Channel’s (public) videos" label="success" auth="any authentication works" %}
{% include doc.html instance="Channel#videos" %}{% include example.html object='channel' method='videos' %}
{% include example.html result='#<Yt::Relation [#<Yt::Video @id=gknz...>, #<Yt::Video @id=32Gc...>, ...]>' %}
{% include dt.html title="Channel’s (public) playlists" label="success" auth="any authentication works" %}
{% include doc.html instance="Channel#playlists" %}{% include example.html object='channel' method='playlists' %}
{% include example.html result='#<Yt::Relation [#<Yt::Playlist @id=PL-L...>, #<Yt::Playlist @id=PL-N...>, ...]>' %}

Before iterating through videos or playlists, use select to specify which parts of each video’s data to load:

{% include doc.html instance="Relation#select" %}{% include example.html object='videos = channel.videos' method='select' params=' :snippet, :statistics' %}
{% include example.html object='videos' method='map &:title' result='["First public video", "Second public video", ...]' %}
{% include example.html object='videos' method='map &:view_count' result='[123, 456, ...]' %}

You can also use limit to only fetch a certain number of videos or playlists:

{% include doc.html instance="Relation#limit" %}{% include example.html object='videos = channel.videos' method='limit' params=' 2' %}
{% include example.html object='videos' method='map &:id' result='["gknzFj_0vvY", "oO6WawhsxTA"]' %}

You can also use size to quickly obtain the estimated number of videos or playlists:

{% include doc.html instance="Relation#size" %}{% include example.html object='channel.videos' method='size' result='312' %}

Note that, due to YouTube API limitations, only a maximum of 500 videos can be fetched for an unauthenticated channel.

{% include dt.html title="Collection of channels" label="success" auth="any authentication works" %}
{% include doc.html class="Channel#where" %}{% include example.html object='Yt::Channel' method='where'  params=' id: ["UCwCnUcLcb9-eSrHa_RQGkQQ", "UCKe_0fJtkT1dYnzn", ...]' %}
{% include example.html result='#<Yt::Relation [#<Yt::Channel @id=UCwCnUcLcb9-eSrHa_RQGkQQ>, ...]>' %}

The previous method returns existing channels that match the provided IDs, skipping any unrecognized ID.
As usual, use select to specify which parts of each channels’s data to load before iterating through the list.

{% include dt.html title="Authenticated account’s channel" label="warning" auth="must authenticate as the channel’s account" %}
{% include doc.html class="Channel#mine" %}{% include example.html object='Yt::Channel' method='mine' %}
{% include example.html result='#<Yt::Channel @id=UCwCnUcLcb9-eSrHa_RQGkQQ>' %}
{% include dt.html title="Channel’s analytics groups" label="warning" auth="must authenticate as the channel’s account" %}
{% include doc.html instance="Channel#groups" %}{% include example.html object='Yt::Channel' method='mine.groups' %}
{% include example.html result='#<Yt::Relation [#<Yt::Group @id=ABVSo3DwAAA>, ...]>' %}