What is a Resource?
Learn about resources and their various types.
We'll cover the following...
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
videoIdorchannelIdproperty 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
partparameter 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_KEYthat we saved earlier. You might seeYOUR_API_KEYin 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.
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.