What is a Resource?
Learn about resources and their various types.
A resource is an individual data entity with a unique identifier. It represents an item that comprises part of the YouTube experience, such as videos, channels, playlists, or captions. The API supports a number of different resources that we can use to retrieve data. We’ll discuss only a few resources in this course.
Types of resources
The table below shows some of the resources that we can interact with using the YouTube Data API.
Resource | Description |
activity | Contains information about an action that a user or a channel has taken on the YouTube site. The actions reported in the activity feeds include sharing a video, rating a video, marking a video as a favorite, and so on. |
channel | Contains information about a YouTube channel, including the number of subscribers, view count, video count, channel name, and description. |
search | Contains information about a YouTube video or channel that matches the search parameters mentioned in the API request. It can be used to get a list of all the videos uploaded on a channel. |
video | Represents a YouTube video. It contains information about a video that matches the search parameters. The information can include the video's title, description, view count, and so forth. |
commentThread | Contains information about a comment thread of a video or channel. The thread consists of a top-level comment and replies to that top-level comment, if any exists. |
i18nRegion | Identifies a geographic area supported by YouTube, which a user can select as their preferred content region. It identifies a region code and a name. |
playlist | Represents a YouTube playlist. A playlist is a collection of videos that we can view successively. |
playlistItem | Identifies another resource, such as a video, included in a YouTube playlist. |
Note: A resource can contain references to other resources. For example, a search result can have either a
videoId
orchannelId
property that identifies a particular video or channel resource, respectively.
Supported methods
The API supports several different methods used to perform functions specific to resources. The following table shows the most common methods that the API supports.
Method | Description |
| Retrieves a list of zero or more resources |
| Creates a new resource |
| Removes a resource |
| Modifies an existing resource |
Using insert
, update
, or delete
methods on a resource always requires user authorization. The list
method supports both authorized and unauthorized requests. Authorized requests can retrieve information about a private user, while unauthorized requests can only retrieve public data.
The diagram below shows all the resource types with their supported methods, type of permission, and return data that we’ll discuss in this course.
Request parameters
When using the API, it’s good to avoid transferring, parsing, and storing unneeded data. For this, the API allows the retrieval of partial resources using two request parameters: part
and fields
. These parameters enable us to identify the resource properties that should be included in the API responses.
The part
parameter
It identifies one or more properties that should be returned for a particular resource. Any API request that retrieves or returns a resource requires the part
parameter. For example, a video
resource has the following parts: snippet
, contentDetails
, fileDetails
, statistics
, status
, and more. These are the most commonly used parts that will be discussed throughout the course.
All of these parts are objects with nested properties. We can think of these objects as groups of metadata fields that the API server might or might not retrieve. We’ll look at these parts in more detail when we discuss each resource in the upcoming lessons.
The fields
parameter
It filters the API response, which only contains the resource parts specified using the part
parameter so that the response only includes a specific set of fields. The fields
parameter also allows you to remove nested properties from an API response.
Note: We cannot use the
part
parameter to filter nested properties from an API response.
Let’s look at the rules and syntax for setting the fields
parameter value.
-
Use a comma-separated list to select multiple fields. For example,
fields=a,b
. -
Use an asterisk as a wildcard to identify all fields. For example,
fields=*
. -
Use parentheses to specify a group of nested properties that will be included in the API response. For example,
fields=a(b,c)
.
Let’s look at some examples to demonstrate the usage of part
and fields
.
Note: For now, we are not using the
API_KEY
that we saved earlier. You might seeYOUR_API_KEY
in the query URL. We can ignore that for now because we will use it later to retrieve data in the upcoming lessons.
Example 1
Suppose that we want the API to respond with a video resource that includes the snippet
and statistics
parts as well as kind
and etag
properties.
API URL:
https://www.googleapis.com/youtube/v3/videos?id=Q7J5qrcPyns&key=YOUR_API_KEY
&part=snippet,statistics
API response:
In the API response below we can see that we have objects for the snippet
and statistics
parts. Each object shows information about the video
resource.
{"items": [{"kind": "youtube#video","etag": "yxVgBpa9AVwYvYemndL8h_qiUxo","id": "Q7J5qrcPyns","snippet": {"publishedAt": "2021-09-20T12:00:09Z","channelId": "UCT_8FqzTIr2Q1BOtvX_DPPw","title": "#77: \"Learning Code by Giving Back\" with Chibuike Nwachukwu of Spleet Africa | Educative Sessions","description": "When Chibuike Nwachukwu began his programming journey in college, it was really difficult for him to find his path. From his ever-changing interests to lack of mentorship and guidance, its a surprise he stayed focused. Now that he's matured, he sees to it that no junior coder he encounters has to go through the many avoidable hassles he went through.\n\nIn our session, Chibuike tells us how helping others helped him become a better coder and also help him find himself along the way. \n\nListen to the podcast HERE: https://www.podbean.com/media/share/pb-226yn-10dc3d7\n(Also available on Apple, Google, Spotify, and more major platforms!)\n\nABOUT OUR GUEST\n\nChibuike Nwachukwu is a self-educated software engineer and technical Writer. He is a passionate problem solver, who enjoys constant learning and knowledge sharing. When not coding, you would find him playing games or forming new partnerships.\nVisit Educative to start your journey into code ►► https://educative.io\n\nDon't forget to subscribe to Educative Sessions on YouTube! \n►► https://www.youtube.com/c/EducativeSessions/?sub_confirmation=1\n\nABOUT EDUCATIVE\n\nEducative (https://educative.io) provides interactive and adaptive courses for software developers. Whether it’s beginning to learn to code, grokking the next interview, or brushing up on frontend coding, data science, or cybersecurity, Educative is changing how developers continue their education. Stay relevant through our pre-configured learning environments that adapt to match a developer’s skill level. Educative provides the best author platform for instructors to create interactive and adaptive content in only a few clicks.\n\nMore Videos from Educative Sessions: https://www.youtube.com/c/EducativeSessions/\n\nSign Up to Speak on Educative Sessions: ►►\nhttp://bit.ly/educative-sessions-s3-signup\n\nEpisode 77: \"Learning Code by Giving Back\" with Chibuike Nwachukwu of Spleet Africa | Educative Sessions","thumbnails": {"default": {"url": "https://i.ytimg.com/vi/Q7J5qrcPyns/default.jpg","width": 120,"height": 90},"medium": {"url": "https://i.ytimg.com/vi/Q7J5qrcPyns/mqdefault.jpg","width": 320,"height": 180},"high": {"url": "https://i.ytimg.com/vi/Q7J5qrcPyns/hqdefault.jpg","width": 480,"height": 360},"standard": {"url": "https://i.ytimg.com/vi/Q7J5qrcPyns/sddefault.jpg","width": 640,"height": 480}}},"statistics": {"viewCount": "121","likeCount": "24","dislikeCount": "0","favoriteCount": "0","commentCount": "16"}}]}
Example 2
Let’s suppose that we want the API to respond with a video resource that includes the snippet
and statistics
parts, but excludes the kind
and etag
and some nested properties in the resource’s snippet
object.
We’ll use the fields
parameter so that in the API response, we only return the channelId
, title
, and categoryId
properties in the resource’s snippet
object.
API URL:
https://www.googleapis.com/youtube/v3/videos?id=Q7J5qrcPyns&key=YOUR_API_KEY&part=snippet,statistics&fields=items(id,snippet(channelId,title,categoryId),statistics)
API response:
The API response below shows that we have objects for the snippet
and statistics
parts highlighted. We do not see the kind
, etag
, and most of the nested properties of the snippet
object that we got in the previous example.
{"items": [{"id": "Q7J5qrcPyns","snippet": {"channelId": "UCT_8FqzTIr2Q1BOtvX_DPPw","title": "#77: \"Learning Code by Giving Back\" with Chibuike Nwachukwu of Spleet Africa | Educative Sessions","categoryId": "28"},"statistics": {"viewCount": "121","likeCount": "24","dislikeCount": "0","favoriteCount": "0","commentCount": "16"}}]}