Translate

Find Videos with the YouTube Search API


YouTube’s massive content library contains billions of videos. If you're building an app, dashboard, or automation tool, you might want to search and retrieve YouTube videos programmatically. That’s where the YouTube Search API, part of the YouTube Data API v3, comes into play.

In this guide, we’ll cover everything you need to know to search YouTube videos using the YouTube API, including:

  • How the YouTube Search API works

  • Setting up your API access

  • Making requests to search videos

  • Filtering by keyword, channel, category, or time

  • Handling and displaying the results


What is the YouTube Search API?

The YouTube Search API is a feature within the YouTube Data API v3 that allows developers to search for public YouTube videos, channels, and playlists.

Using a single HTTP request, you can query YouTube by keywords and receive a structured JSON response containing video details like:

  • Video ID

  • Title

  • Description

  • Thumbnails

  • Channel name

  • Publish date

This enables developers to power custom search engines, bots, dashboards, content analyzers, and more.


Step 1: Get Your YouTube API Key

To use the API, you need a free API key from Google.

Steps:

  1. Go to https://console.developers.google.com/

  2. Create a new project or select an existing one.

  3. Click on “APIs & Services” → Library

  4. Search for YouTube Data API v3, and click Enable

  5. Go to Credentials, and click Create Credentials → API Key

  6. Copy your API key and keep it secure


Step 2: Make a Basic Search Request

YouTube API uses a simple HTTP GET request. Here's the basic format:

https://www.googleapis.com/youtube/v3/search?part=snippet&q=YOUR_QUERY&type=video&key=YOUR_API_KEY

Example:

To search for “how to cook biryani”:

https://www.googleapis.com/youtube/v3/search?part=snippet&q=how+to+cook+biryani&type=video&maxResults=5&key=YOUR_API_KEY

Parameters explained:

  • part=snippet: Fetches video metadata like title, thumbnails, etc.

  • q=how+to+cook+biryani: Your search query

  • type=video: Only return videos (not channels or playlists)

  • maxResults=5: Number of results per page (max is 50)

  • key=YOUR_API_KEY: Your API key


Step 3: Parse the Response

The response is a JSON object. Each item includes details like this:

{
  "items": [
    {
      "id": {
        "videoId": "AbCdEf12345"
      },
      "snippet": {
        "title": "How to Cook Biryani - Step by Step",
        "description": "Learn how to make delicious biryani...",
        "thumbnails": {
          "default": {
            "url": "https://i.ytimg.com/vi/AbCdEf12345/default.jpg"
          }
        },
        "channelTitle": "Indian Food TV",
        "publishedAt": "2023-11-01T14:23:45Z"
      }
    }
  ]
}

From here, you can extract:

  • videoId

  • title

  • description

  • thumbnail.url

  • channelTitle

  • publishedAt

To generate a link to the video:

https://www.youtube.com/watch?v=AbCdEf12345

Step 4: Advanced Search Filters

The API allows multiple filters to refine results.

1. Filter by Upload Date

Use the publishedAfter or publishedBefore parameters (in ISO 8601 format):

&publishedAfter=2024-01-01T00:00:00Z

2. Filter by Channel

Search only within a specific channel:

&channelId=UCx123abcXYZ

You can get a channel's ID from their "About" section or via another API call.

3. Order Results

Choose how results are sorted:

  • order=date (most recent)

  • order=rating

  • order=relevance (default)

  • order=title

  • order=viewCount

Example:

&order=viewCount

4. Filter by Video Duration

  • videoDuration=short (less than 4 minutes)

  • videoDuration=medium (4–20 minutes)

  • videoDuration=long (more than 20 minutes)


Step 5: Pagination and More Results

YouTube Search API returns a maximum of 50 results per page. To get more results, use the nextPageToken from the response.

Example structure:

{
  "nextPageToken": "CBkQAA",
  "items": [...]
}

Use that token in your next request:

&pageToken=CBkQAA

Step 6: Example with JavaScript (Browser)

<!DOCTYPE html>
<html>
<head><title>YouTube Search</title></head>
<body>
  <input id="query" placeholder="Search...">
  <button onclick="search()">Search</button>
  <div id="results"></div>

  <script>
    async function search() {
      const q = document.getElementById('query').value;
      const res = await fetch(`https://www.googleapis.com/youtube/v3/search?part=snippet&q=${encodeURIComponent(q)}&type=video&maxResults=5&key=YOUR_API_KEY`);
      const data = await res.json();
      const results = document.getElementById('results');
      results.innerHTML = '';

      data.items.forEach(item => {
        const videoId = item.id.videoId;
        const title = item.snippet.title;
        const thumb = item.snippet.thumbnails.default.url;

        results.innerHTML += `<div>
          <img src="${thumb}"> <a href="https://youtube.com/watch?v=${videoId}" target="_blank">${title}</a>
        </div>`;
      });
    }
  </script>
</body>
</html>

Just replace YOUR_API_KEY with your actual key, and you have a working search tool.


Quota & Limits

  • YouTube Search requests cost 100 quota units each.

  • Your API project gets 10,000 units/day by default.

  • You can request more quota from Google if needed.


Use Cases

  • Build a custom search engine

  • Monitor niche content for trends

  • Pull video metadata into a spreadsheet or app

  • Filter competitor content

  • Alert system for new uploads


Common Errors

403 Quota Exceeded
You’ve used up your daily quota. Try reducing the number of requests or apply for a quota increase.

400 Missing Required Parameter
Check that all required parameters like part=snippet are included.

API Key Not Valid
Make sure your API key is active and authorized to access the YouTube Data API.


Conclusion

The YouTube Search API is a powerful and flexible tool for developers, analysts, and content managers. Whether you want to track video performance, build your own frontend search, or automate reporting, the API gives you direct access to YouTube’s public video data.

By learning how to construct requests, apply filters, and parse results, you can create efficient workflows and tools tailored to your project.

If you’re interested in building on this, consider looking into the YouTube Analytics API or integrating search results into Google Sheets or Apps Script for powerful reporting dashboards.