--- title: "Yt::PlaylistItem" h2: "Playlist items" ---

Yt::PlaylistItem represents a YouTube playlist item. Initialize using its YouTube ID:

{% highlight ruby %} item = Yt::PlaylistItem.new id: 'UEwtTGVUdXRjOUdSS0Qze' # => # {% endhighlight %}

Authentication

Most methods of Yt::PlaylistItem retrieve public data from YouTube (e.g.: fetch an item’s position).
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 item = Yt::PlaylistItem.new id: 'UEwtTGVUdXRjOUdSS0Qze' ## use any playlist item ID item.position # => 0 {% endhighlight %}

Other methods acts on behalf of YouTube accounts (e.g.: add an item to a playlist).
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 Yt::PlaylistItem.insert playlist_id: 'PL-LeTutc9GRKD3DhnRF_y', video_id: 'gknzFj_0vvY' # => # {% endhighlight %}

List of Yt::PlaylistItem data methods

{% include dt.html title="Playlist item’s snippet" label="success" auth="any authentication works" %}
{% include doc.html instance="PlaylistItem#id" %}{% include example.html object='item' method='id' result='"UEwtTGVUdXRjOUdSS0Qze"' %}
{% include doc.html instance="PlaylistItem#title" %}{% include example.html object='item' method='title' result='"First public video"' %}
{% include doc.html instance="PlaylistItem#description" %}{% include example.html object='item' method='description' result='"A YouTube video to test the yt gem."' %}
{% include doc.html instance="PlaylistItem#published_at" %}{% include example.html object='item' method='published_at' result='2016-11-18 23:40:55 UTC' %}
{% include doc.html instance="PlaylistItem#thumbnail_url" %}{% include example.html object='item' method='thumbnail_url' result='"https://i.ytimg.com/vi/gknzFj_0vvY/default.jpg"' %}
{% include doc.html instance="PlaylistItem#channel_id" %}{% include example.html object='item' method='channel_id' result='"UCwCnUcLcb9-eSrHa_RQGkQQ"' %}
{% include doc.html instance="PlaylistItem#channel_title" %}{% include example.html object='item' method='channel_title' result='"Yt Test"' %}
{% include doc.html instance="PlaylistItem#playlist_id" %}{% include example.html object='item' method='playlist_id' result='"PL-LeTutc9GRKD3yBDhnRF_yE8UTaQI5Jf"' %}
{% include doc.html instance="PlaylistItem#position" %}{% include example.html object='item' method='position' result='0' %}
{% include doc.html instance="PlaylistItem#video_id" %}{% include example.html object='item' method='video_id' result='"gknzFj_0vvY"' %}
{% include dt.html title="Playlist item’s status" label="success" auth="any authentication works" %}
{% include doc.html instance="PlaylistItem#privacy_status" %}{% include example.html object='item' method='privacy_status' result='"public"' %}

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

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

{% include doc.html instance="PlaylistItem#select" %}{% include example.html object='fast = item' 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 item’s snippet and status' %}
{% include example.html object='fast' method='privacy_status' result='=> no extra HTTP requests' %}
{% include dt.html title="Adding and removing a playlist item" label="warning" auth="must authenticate as the channel’s account" %}
{% include doc.html class="PlaylistItem#insert" %}{% include example.html object='item = Yt::PlaylistItem' method='insert' params=' playlist_id: "PL-...", video_id: "gknzFj_0vvY"' %}
{% include doc.html instance="PlaylistItem#delete" %}{% include example.html object='item' method='delete' result='true' %}