Implementation and Migration: Favorites

The following examples show how to use the YouTube Data API (v3) to perform functions related to favorite videos.

Retrieve a user's favorite videos

YouTube Data API (v2) functionality: Retrieving a user's favorite videos

This example retrieves the favorite videos for a particular channel. The example has two steps:

Add a favorite video

YouTube Data API (v2) functionality: Adding a favorite video

This example adds a favorite video for a channel. This request must be authorized using OAuth 2.0. This example has two steps:

  • Step 1: Retrieve the playlist ID for the channel's favorite videos

    Follow the instructions in step 1 of the example for retrieving a user's favorite videos to obtain the playlist ID for the channel's list of favorite videos.

  • Step 2: Add a video to the channel's list of favorites

    Call the playlistItems.insert method to add a video to the channel's list of favorites. This request must be authorized using OAuth 2.0. The request body is a playlistItem resource that specifies at least the following values:

    • The snippet.playlistId identifies the playlist to which you are adding the favorite video. This is the playlist ID you obtained in step 1.
    • The snippet.resourceId.kind contains the value youtube#video.
    • The snippet.resourceId.videoId identifies the video that you are adding as a favorite. The property value is a unique YouTube video ID.

    The API request below will Rick Roll your list of favorite videos. The request body is:

    {
      "snippet": {
        "playlistId": "PLAYLIST_ID",
        "resourceId": {
          "kind": "youtube#video",
          "videoId": "dQw4w9WgXcQ"
        }
      }
    }

    To complete the request in the APIs Explorer, you need to set the snippet.playlistId property's value.

    https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.playlistItems.insert?
            part=snippet

    Note: The documentation for the playlistItems.insert method identifies the other property values you can set when adding a playlist item.

Delete a favorite video

YouTube Data API (v2) functionality: Deleting a favorite video

This example deletes a favorite video from a channel's list of favorites. This request must be authorized using OAuth 2.0. This example has three steps:

  • Step 1: Retrieve the playlist ID for the channel's favorite videos

    Follow the instructions in step 1 of the example for retrieving a user's favorite videos to obtain the playlist ID for the channel's list of favorite videos.

  • Step 2: Retrieve the list of items in the playlist

    Call the playlistItems.list method to retrieve the channel's list of favorite videos. Set the playlistId parameter's value to the playlist ID that you obtained in step 1.

    The id property for each resource in the API response identifies the playlist item ID that uniquely identifies that item. You will use that value to remove an item from the list in the next step.

  • Step 3: Delete a video from the channel's list of favorites

    Call the playlistItems.delete method to remove a video from the playlist. Set the request's id parameter to the playlist item ID for the item you want to remove. This request must be authorized using OAuth 2.0.

    Note that the playlist item ID used to identify a video in a playlist is different than the YouTube video ID that uniquely identifies the video. The playlist item ID identifies the video as an item in a particular playlist.

    To complete the request in the APIs Explorer, you need to set the id property's value.

    https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.playlistItems.delete?
            id=PLAYLIST_ITEM_ID

Send feedback about...

YouTube Data API
YouTube Data API