Channels
Yt::Channel
represents a YouTube channel.
Initialize using either the YouTube ID or URL:
Some methods from other classes also return a Yt::Channel
object
(e.g.: Yt::Account#channel
) or a collection of Yt::Channel
objects (e.g.: Yt::Account#subscribed_channels
).
Authentication
Most methods of Yt::Channel
retrieve public data from YouTube (e.g.: fetch a channel’s title and videos).
To use these methods (marked with below), you only need to get a Server API key from Google and configure:
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, obtain an access or refresh token from the account you want to act as, and pass the account as the :auth
parameter:
Lastly, some methods acts on behalf of YouTube content owners (e.g.: fetch the earnings of a channel).
To use these methods (marked with below), you need to get an API Client ID/Secret from Google, obtain an access or refresh token from the content owner, and pass the content owner as the :auth
parameter:
List of Yt::Channel
methods
- any authentication works Channel’s Snippet
→ Yt docs
channel.id # => "UCxO1tY8h1AhOz0T4ENwmpow"
→ Yt docschannel.title # => "Fullscreen"
→ Yt docschannel.description # => "The media company for the connected generation"
→ Yt docschannel.published_at # => 2006-03-23 06:13:25 UTC
→ Yt docschannel.thumbnail_url # => "https://yt3.ggpht.com/-KMnbKDBl60w/photo.jpg"
- any authentication works Channel’s Statistics
- any authentication works Channel’s Privacy Status
- must authenticate as another channel’s account Channel’s Subscription
- must authenticate as the channel’s account or content owner Channel’s Updates
→ Yt docs
channel.delete_playlists title: /2013$/ # => [true, true]
- must authenticate as the channel’s content owner Channel’s Content Owner Details
- any authentication works Channel’s Associations
- must authenticate as the channel’s content owner Channel’s Monetization
List of Yt::Channel
analytics methods
By default, analytics methods return the total value for the lifetime of a channel (e.g., all the views of a channel).
To set specific starting and ending dates, use the :since
and :until
options.
To obtain one value per each day of the range you specify (rather than the total), use the by: :day
option.
To limit the results to a specific location, use the :in
option .
For brevity, the options above are omitted in the examples below.
- must authenticate as the channel’s account or content owner Channel’s Analytics
-
→ Yt docs
channel.views # => {total: 345}
→ Yt docschannel.comments # => {total: 900}
→ Yt docschannel.likes # => {total: 934}
→ Yt docschannel.dislikes # => {total: 445}
→ Yt docschannel.shares # => {total: 913}
→ Yt docschannel.subscribers_gained # => {total: 334}
→ Yt docschannel.subscribers_lost # => {total: 345}
→ Yt docschannel.videos_added_to_playlists # => {total: 334}
→ Yt docschannel.videos_removed_from_playlists # => {total: 987}
→ Yt docschannel.average_view_duration # => {total: 10}
→ Yt docschannel.average_view_percentage # => {total: 34.3}
→ Yt docschannel.annotation_clicks # => {total: 91}
→ Yt docschannel.annotation_click_through_rate # => {total: 2.98}
→ Yt docschannel.annotation_close_rate # => {total: 3.34}
→ Yt docschannel.estimated_minutes_watched # => {total: 12}
→ Yt docschannel.card_impressions # => {total: 3}
→ Yt docschannel.card_clicks # => {total: 3}
→ Yt docschannel.card_click_rate # => {total: 0.65}
→ Yt docschannel.card_teaser_impressions # => {total: 3}
→ Yt docschannel.card_teaser_clicks # => {total: 3}
→ Yt docschannel.card_teaser_click_rate # => {total: 0.65}
→ Yt docschannel.views by: :country # => {"US" => 33, "MX" => 12, …}
→ Yt docschannel.comments by: :country # => {"US" => 17, "FR" => 12, …}
→ Yt docschannel.likes by: :country # => {"US" => 32, "SG" => 3, …}
→ Yt docschannel.dislikes by: :country # => {"US" => 87, "MT" =>…}
→ Yt docschannel.shares by: :country # => {"US" => 44, "GR" => 7, …}
→ Yt docschannel.subscribers_gained by: :country # => {"CO" => 32, …}
→ Yt docschannel.subscribers_lost by: :country # => {"BM" => 1, …}
→ Yt docschannel.favorites_added by: :country # => {"BG" => 181, …}
→ Yt docschannel.favorites_removed by: :country # => {"PA" => 0, …}
→ Yt docschannel.videos_added_to_playlists by: :country # => {"BG" => 181, …}
→ Yt docschannel.videos_removed_from_playlists by: :country # => {"PA" => 0, …}
→ Yt docschannel.average_view_duration by: :country # => {"AW" => 456, …}
→ Yt docschannel.average_view_percentage by: :country # => {"PK" => 38.85, …}
→ Yt docschannel.annotation_clicks by: :country # => {"GT" => 329, …}
→ Yt docschannel.annotation_click_through_rate by: :country # => {"US" => …}
→ Yt docschannel.annotation_close_rate by: :country # => {"ZW" => 0.1, …}
→ Yt docschannel.estimated_minutes_watched by: :country # => {"US" => 12, …}
→ Yt docschannel.views by: :state # => {"TX" => 42, "SD" => 33, …}
→ Yt docschannel.average_view_duration by: :state # => {"CA" => 456, …}
→ Yt docschannel.average_view_percentage by: :state # => {"IL" => 38.85, …}
→ Yt docschannel.annotation_clicks by: :state # => {"TX" => 329, …}
→ Yt docschannel.annotation_click_through_rate by: :state # => {"TX" => …}
→ Yt docschannel.annotation_close_rate by: :state # => {"TX" => 0.1, …}
→ Yt docschannel.estimated_minutes_watched by: :state # => {"TX" => 12, …}
→ Yt docschannel.views by: :video # => {#<Yt::Video @id=…> => 9, …}
→ Yt docschannel.views by: :playlist, includes: [:status] # => {#<Yt::Playlist> => …}
→ Yt docschannel.views by: :traffic_source # => {advertising: 53, channel: 7, …}
→ Yt docschannel.views by: :playback_location # => {watch: 467, embedded: 53, …}
→ Yt docschannel.views by: :embedded_player_location # => {"fullscreen.net" => 9, …}
→ Yt docschannel.views by: :device_type # => {mobile: 457, tv: 954, …}
→ Yt docschannel.views by: :subscribed_status # => {subscribed: 57, unsubscribed: 54}
→ Yt docschannel.views by: :related_video # => {#<Yt::Video @id=…> => 7, …}
→ Yt docschannel.views by: :search_term # => {"fullscreen" => 7, "music" => 3, …}
→ Yt docschannel.views by: :referrer # => {"Google Search" => 7, "ytimg.com" => 3, …}
→ Yt docschannel.estimated_minutes_watched by: :video # => {#<Yt::Video> => 9, …}
→ Yt docschannel.estimated_minutes_watched by: :playlist # => {#<Yt::Playlist> => …}
→ Yt docschannel.estimated_minutes_watched by: :traffic_source # => {channel: 7, …}
→ Yt docschannel.estimated_minutes_watched by: :playback_location # => {watch: 1, …}
→ Yt docschannel.estimated_minutes_watched by: :embedded_player_location # => {…}
→ Yt docschannel.estimated_minutes_watched by: :device_type # => {tv: 954, …}
→ Yt docschannel.estimated_minutes_watched by: :related_video # => {#<Yt::Video> => …}
→ Yt docschannel.estimated_minutes_watched by: :search_term # => {"music" => 7, …}
→ Yt docschannel.estimated_minutes_watched by: :referrer # => {"Facebook" => 7, …}
→ Yt docschannel.viewer_percentage # => {female: {'18-24' => 4.12, '25-34' => …}, …}
→ Yt docschannel.viewer_percentage by: :gender # => {female: 12.3, male: 87.7}
→ Yt docschannel.viewer_percentage by: :age_group # => {'18-24' => 4.1, '25-34' => …}
→ Yt docschannel.reports only: [:views, :shares] # => {views: {…}, shares: {…}}