List Our YouTube Channels
Learn about listing a channel using the YouTube Data API.
We'll cover the following
In this lesson, we’ll look at the list
method of the Channels
resource, which is used to list any channel data, such as channel title and description.
List a channel
In this section, we’ll list a specific channel that will be fetched according to the channel ID we passed in the query parameters. To list a channel, we’ll send a GET
HTTP request to the following URL:
https://www.googleapis.com/youtube/v3/channels
Request parameters
Here are some important parameters that we can use to call the endpoint:
Name | Type | Category | Description |
| String | Required | This parameter will specify all the resource properties that will be returned in the response fields. A user can set multiple comma-separated resource properties from the following options: |
| String | Optional | Filters the channel list based on the username. |
| String | Optional | Filters the channel list by channel ID. A comma-separated list of multiple channel IDs can be provided. |
| Boolean | Optional | Filters the channel list that is managed by the user. |
| Boolean | Optional | Filters the channel list owned by the user. |
| Integer | Optional | Used to specify the number of the response result. |
Note: To call this endpoint, a user must provide one parameter from
id
,mine
,forUsername
, ormanagedByMe
.
Let’s call the API endpoint to filter the list of channels with our channel ID. Click the “Run” button to execute the code.
import fetch from 'node-fetch';// Define endpoint URL hereconst endpointUrl = new URL('https://www.googleapis.com/youtube/v3/channels');// Define Header Parameters hereconst headerParameters = {Authorization: 'Bearer {{ACCESS_TOKEN}}',Accept: 'application/json',};// Define Query Parameters hereconst queryParameters = new URLSearchParams({part: 'snippet,id',id: '{{CHANNEL_ID}}',});// Setting API call optionsconst options = {method: 'GET',headers: headerParameters,};// Function to make API callasync function listChannel() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);// Printing responseprintResponse(response);} catch (error) {// Printing error messageprintError(error);}}// Calling function to make API calllistChannel();
Let’s understand how the above code works by breaking it down:
Lines 7–10: We declare the headers by using the
headerParameters
variable in which we pass theACCESS_TOKEN
.Lines 13–16: We declare the query parameters variable in which we define the
part
andid
query parameters to filter the channels by using channel IDs.Line 25: We define an
async
function namedlistChannel()
, which is used to make an API call to the endpoint.
Response fields
The endpoint response field contains channel data. The most important ones are as follows:
Name | Type | Description |
| String | Reflects the resource type of the API call. |
| String | Contains the resource ETag. |
| Integer | Contains the number of results of the API response. |
| List | Contains the list of channels that matches the request requirements. |