<commit_before>---
title:  "Yt::Channel"
h2: "Channels"
---

<p>
  <code>Yt::Channel</code> represents a <a href="https://developers.google.com/youtube/v3/docs/channels">YouTube channel</a>.
  Initialize using its YouTube ID:
</p>

<dl>
  <dd><a class="anchor" id="new"></a><div class="highlight"><pre>
{% include doc.html instance="Channel#initialize" %}{% include example.html object='channel = <span class="no">Yt</span><span class="o">::</span><span class="no">Channel</span>' method='new' params=' <span class="ss">id:</span> <span class="s1">"UCwCnUcLcb9-eSrHa_RQGkQQ"</span>' %}
{% include example.html result='#&lt;Yt::Channel @id=UCwCnUcLcb9-eSrHa_RQGkQQ&gt;' %}</pre>
  </div></dd>
</dl>

<hr />
<h4>Authentication</h4>

<p>
  Most methods of <code>Yt::Channel</code> <strong>retrieve public data</strong> from YouTube (e.g.: fetch a channel’s title).<br />
  To use these methods (marked with <span class="label label-success">&nbsp;</span> below), you only need to <a href="{{ site.baseurl }}/#api_key">generate an API key</a> and configure:
</p>

{% highlight ruby %}
Yt.configuration.api_key = "<your api key>"                      ## use your API key

channel = Yt::Channel.new id: 'UCwCnUcLcb9-eSrHa_RQGkQQ'         ## use any channel ID
channel.title # => "Yt Test"
{% endhighlight %}

<p>
  Other methods <strong>act on behalf of YouTube accounts</strong> (e.g.: access the analytics of a channel).<br />
  To use these methods (marked with  <span class="label label-warning">&nbsp;</span> below), you need to <a href="{{ site.baseurl }}/#oauth_client">generate an OAuth client</a>, <a href="{{ site.baseurl }}/#refresh_token">obtain a refresh token</a> from the account you want to act as, and pass the account as the <code>:auth</code> parameter:
</p>

{% highlight ruby %}
Yt.configuration.client_id = "<your ID>"            ## replace with your client ID
Yt.configuration.client_secret = "<your secret>"    ## replace with your client secret
auth = Yt::Account.new refresh_token: "<your refresh token>"

channel = Yt::Channel.new id: "<your channel ID>", auth: auth
channel.views # => {total: 345} (the total views of your channel)
{% endhighlight %}


<p>
  Lastly, some methods <strong>act on behalf of YouTube content owners</strong> (e.g.: fetch the earnings of a channel).<br />
  To use these methods (marked with  <span class="label label-danger">&nbsp;</span> below), you need to you need to <a href="{{ site.baseurl }}/#oauth_client">generate an OAuth client</a>, <a href="{{ site.baseurl }}/#refresh_token">obtain a refresh token</a> from the content owner, and pass the content owner as the <code>:auth</code> parameter:
</p>

{% highlight ruby %}
Yt.configuration.client_id = "<your ID>"            ## replace with your client ID
Yt.configuration.client_secret = "<your secret>"    ## replace with your client secret
auth = Yt::ContentOwner.new id: "<your content owner ID>", refresh_token: "<token>"

channel = Yt::Channel.new id: "<your channel ID>", auth: auth
channel.ad_impressions # => {total: 123} (the total ad impressions of your channel)
{% endhighlight %}

<hr />
<h4>List of <code>Yt::Channel</code> data methods</h4>
<dl>
  {% include dt.html title="Channel’s snippet" label="success" auth="any authentication works" %}
  <dd><a class="anchor" id="snippet"></a><div class="highlight"><pre>
{% 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#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"' %}</pre>
  </div></dd>

  {% include dt.html title="Channel’s status" label="success" auth="any authentication works" %}
  <dd><a class="anchor" id="status"></a><div class="highlight"><pre>
{% 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_upload_status" %}{% include example.html object='channel' method='long_upload_status' result='"longUploadsUnspecified"' %}</pre>
  </div></dd>

  {% include dt.html title="Channel’s statistics" label="success" auth="any authentication works" %}
  <dd><a class="anchor" id="statistics"></a><div class="highlight"><pre>
{% 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' %}</pre>
  </div></dd>
</dl>
<p>
  To limit the number of HTTP requests, use <code>select</code> to specify which <a href="https://developers.google.com/youtube/v3/docs/channels/list#part">parts</a> of the channel’s data to load:
</p>
<dl>
  <dd><a class="anchor" id="select"></a><div class="highlight"><pre>
{% 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=' <span class="ss">:snippet</span><span class="p">,</span> <span class="ss">:status</span>' 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' %}</pre>
  </div></dd>
</dl>

<dl>
  {% include dt.html title="Channel’s (public) videos" label="success" auth="any authentication works" %}
  <dd><a class="anchor" id="videos"></a><div class="highlight"><pre>
{% include doc.html instance="Channel#videos" %}{% include example.html object='channel' method='videos' %}
{% include example.html result='#&lt;Yt::Relation [#&lt;Yt::Video @id=gknz...&gt;, #&lt;Yt::Video @id=32Gc...&gt;, ...]&gt;' %}</pre>
  </div></dd>
</dl>
<dl>
  {% include dt.html title="Channel’s (public) playlists" label="success" auth="any authentication works" %}
  <dd><a class="anchor" id="playlists"></a><div class="highlight"><pre>
{% include doc.html instance="Channel#playlists" %}{% include example.html object='channel' method='playlists' %}<commit_msg>Remove extra `=>` from docs<commit_after>---
title:  "Yt::Channel"
h2: "Channels"
---

<p>
  <code>Yt::Channel</code> represents a <a href="https://developers.google.com/youtube/v3/docs/channels">YouTube channel</a>.
  Initialize using its YouTube ID:
</p>

<dl>
  <dd><a class="anchor" id="new"></a><div class="highlight"><pre>
{% include doc.html instance="Channel#initialize" %}{% include example.html object='channel = <span class="no">Yt</span><span class="o">::</span><span class="no">Channel</span>' method='new' params=' <span class="ss">id:</span> <span class="s1">"UCwCnUcLcb9-eSrHa_RQGkQQ"</span>' %}
{% include example.html result='#&lt;Yt::Channel @id=UCwCnUcLcb9-eSrHa_RQGkQQ&gt;' %}</pre>
  </div></dd>
</dl>

<hr />
<h4>Authentication</h4>

<p>
  Most methods of <code>Yt::Channel</code> <strong>retrieve public data</strong> from YouTube (e.g.: fetch a channel’s title).<br />
  To use these methods (marked with <span class="label label-success">&nbsp;</span> below), you only need to <a href="{{ site.baseurl }}/#api_key">generate an API key</a> and configure:
</p>

{% highlight ruby %}
Yt.configuration.api_key = "<your api key>"                      ## use your API key

channel = Yt::Channel.new id: 'UCwCnUcLcb9-eSrHa_RQGkQQ'         ## use any channel ID
channel.title # => "Yt Test"
{% endhighlight %}

<p>
  Other methods <strong>act on behalf of YouTube accounts</strong> (e.g.: access the analytics of a channel).<br />
  To use these methods (marked with  <span class="label label-warning">&nbsp;</span> below), you need to <a href="{{ site.baseurl }}/#oauth_client">generate an OAuth client</a>, <a href="{{ site.baseurl }}/#refresh_token">obtain a refresh token</a> from the account you want to act as, and pass the account as the <code>:auth</code> parameter:
</p>

{% highlight ruby %}
Yt.configuration.client_id = "<your ID>"            ## replace with your client ID
Yt.configuration.client_secret = "<your secret>"    ## replace with your client secret
auth = Yt::Account.new refresh_token: "<your refresh token>"

channel = Yt::Channel.new id: "<your channel ID>", auth: auth
channel.views # => {total: 345} (the total views of your channel)
{% endhighlight %}


<p>
  Lastly, some methods <strong>act on behalf of YouTube content owners</strong> (e.g.: fetch the earnings of a channel).<br />
  To use these methods (marked with  <span class="label label-danger">&nbsp;</span> below), you need to you need to <a href="{{ site.baseurl }}/#oauth_client">generate an OAuth client</a>, <a href="{{ site.baseurl }}/#refresh_token">obtain a refresh token</a> from the content owner, and pass the content owner as the <code>:auth</code> parameter:
</p>

{% highlight ruby %}
Yt.configuration.client_id = "<your ID>"            ## replace with your client ID
Yt.configuration.client_secret = "<your secret>"    ## replace with your client secret
auth = Yt::ContentOwner.new id: "<your content owner ID>", refresh_token: "<token>"

channel = Yt::Channel.new id: "<your channel ID>", auth: auth
channel.ad_impressions # => {total: 123} (the total ad impressions of your channel)
{% endhighlight %}

<hr />
<h4>List of <code>Yt::Channel</code> data methods</h4>
<dl>
  {% include dt.html title="Channel’s snippet" label="success" auth="any authentication works" %}
  <dd><a class="anchor" id="snippet"></a><div class="highlight"><pre>
{% 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#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"' %}</pre>
  </div></dd>

  {% include dt.html title="Channel’s status" label="success" auth="any authentication works" %}
  <dd><a class="anchor" id="status"></a><div class="highlight"><pre>
{% 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_upload_status" %}{% include example.html object='channel' method='long_upload_status' result='"longUploadsUnspecified"' %}</pre>
  </div></dd>

  {% include dt.html title="Channel’s statistics" label="success" auth="any authentication works" %}
  <dd><a class="anchor" id="statistics"></a><div class="highlight"><pre>
{% 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' %}</pre>
  </div></dd>
</dl>
<p>
  To limit the number of HTTP requests, use <code>select</code> to specify which <a href="https://developers.google.com/youtube/v3/docs/channels/list#part">parts</a> of the channel’s data to load:
</p>
<dl>
  <dd><a class="anchor" id="select"></a><div class="highlight"><pre>
{% 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=' <span class="ss">:snippet</span><span class="p">,</span> <span class="ss">:status</span>' 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' %}</pre>
  </div></dd>
</dl>

<dl>
  {% include dt.html title="Channel’s (public) videos" label="success" auth="any authentication works" %}
  <dd><a class="anchor" id="videos"></a><div class="highlight"><pre>
{% include doc.html instance="Channel#videos" %}{% include example.html object='channel' method='videos' %}
{% include example.html result='#&lt;Yt::Relation [#&lt;Yt::Video @id=gknz...&gt;, #&lt;Yt::Video @id=32Gc...&gt;, ...]&gt;' %}</pre>
  </div></dd>
</dl>
<dl>
  {% include dt.html title="Channel’s (public) playlists" label="success" auth="any authentication works" %}
  <dd><a class="anchor" id="playlists"></a><div class="highlight"><pre>
{% include doc.html instance="Channel#playlists" %}{% include example.html object='channel' method='playlists' %}
{'fraction_non_alphanumeric': 0.18434410900347314, 'fraction_numerical': 0.006411969008816457, 'mean_word_length': 5.903181189488244, 'pattern_counts': {'":': 0, '<': 293, '<?xml version=': 0, '>': 302, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '611634', 'n_tokens_mistral': 4895, 'n_tokens_neox': 4594, 'n_words': 1277}