Unlock YouTube Insights with Content Search and Info API

24 Jun 2025
Unlock YouTube Insights with Content Search and Info API

The YouTube Content Search and Info API offers developers a powerful toolkit for integrating YouTube's vast content resources into their applications. By leveraging this API, developers can effortlessly search for videos, channels, and playlists while also retrieving detailed information about specific content. This simplification not only saves time but also enhances the user experience by providing access to trending videos, channel details, and user comments with just a few API calls.

Common use cases for this API include creating music apps that showcase trending songs, developing educational platforms that curate relevant video content, and integrating social media features that allow users to view and engage with comments on videos.

Prerequisites

To use the YouTube Content Search and Info API, you'll need a valid API key and a basic understanding of how to make API calls.

Retrieve YouTube Channel Videos

This action allows you to fetch videos from a specific YouTube channel using its unique identifier. It supports options for pagination and filtering, making it easier to manage large sets of results.

Purpose

The action solves the problem of accessing a channel's video library efficiently, allowing developers to present a curated list of videos from specific creators.

Input Requirements

  • next: (string) Token for paginating through results.
  • sort: (string) Specifies the order of results.
  • filter: (string) Criteria for filtering results.
  • identifier: (string) Unique identifier for the requested channel.

Expected Output

The output includes details about the channel, such as the title, avatar, description, and a list of videos.

Use Cases

  • Displaying a channel's video content on a website.
  • Creating a video playlist based on a specific channel.
  • Integrating channel information into a content management system.

```python
import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "1c17ebd4-c6e2-49ed-81c3-27b8f53707bf" # Action ID for: Retrieve YouTube Channel Videos

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "next": "4qmFsgKFARIYVUNpVEdLQTlXMEcwVEw4SG03VWZfdTlBGjpFZ1oyYVdSbGIzTVlBeUFBTUFFNEFlb0RGa05uUVZORFoycHdNazVFTkRWT2VVcHNhMmR2VFdjJTNEmgIsYnJvd3NlLWZlZWRVQ2lUR0tBOVcwRzBUTDhIbTdVZl91OUF2aWRlb3MxMDI%3D",
  "sort": "n",
  "identifier": "UCiTGKA9W0G0TL8Hm7Uf_u9A"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body (non-JSON): {e.response.text}")
    print("------------------------------------------------")


## Fetch Trending YouTube Videos
This action retrieves a list of trending videos from YouTube, allowing customization based on country and language preferences.

### Purpose
It provides developers with a way to display the latest popular content, ensuring users are always engaged with current trends.

### Input Requirements
- **countryCode**: (string) Represents the country for trending content.
- **requestType**: (string) Type of request being made.
- **languageCode**: (string) Represents the language for the content.

### Expected Output
The output contains a list of trending videos, including video titles, lengths, channels, and view counts.

### Use Cases
- Building a homepage for a video platform that showcases trending content.
- Curating playlists based on popular videos in specific regions.
- Enhancing user engagement by providing fresh, relevant video suggestions.

import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "6f2e1211-7291-46d9-a385-9b344d4bca69" # Action ID for: Fetch Trending YouTube Videos

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "countryCode": "US",
  "requestType": "mu",
  "languageCode": "en"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body (non-JSON): {e.response.text}")
    print("------------------------------------------------")


## Retrieve YouTube Video Comments
This action fetches comments for a specified YouTube video, supporting pagination and sorting options.

### Purpose
It allows developers to access user engagement data, providing insights into viewer sentiments and discussions around specific videos.

### Input Requirements
- **next**: (string) Token for pagination.
- **requestId**: (string) Unique identifier for tracking the request.

### Expected Output
The output includes a list of comments, each with details such as text, likes, author information, and timestamps.

### Use Cases
- Displaying user comments below videos in an application.
- Analyzing viewer feedback to improve content strategies.
- Creating community features that allow for direct engagement with video content.

import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "8c99b800-eda5-429c-8db5-1c85995bca53" # Action ID for: Retrieve YouTube Video Comments

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "next": "Eg0SC1lRSHNYTWdsQzlBGAYyJSIRIgtZUUhzWE1nbEM5QTAAeAJCEGNvbW1lbnRzLXNlY3Rpb24%3D",
  "requestId": "YQHsXMglC9A"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body (non-JSON): {e.response.text}")
    print("------------------------------------------------")


## Execute YouTube Content Search
This action enables comprehensive searches on YouTube, allowing developers to find videos, channels, and playlists using multiple filters.

### Purpose
It addresses the need for flexible search capabilities, enabling users to locate content that precisely matches their interests.

### Input Requirements
- **next**: (string) Token for fetching next results.
- **sort**: (string) Sorting parameter.
- **type**: (string) Type of content to fetch.
- **query**: (string) Text query for searching content.
- **region**: (string) Geographic filter for results.
- **duration**: (string) Desired content duration.
- **features**: (string) Filters for special content features.
- **language**: (string) Preferred content language.
- **uploadDate**: (string) Timeframe for uploaded content.

### Expected Output
The output includes a list of search results, containing video details and a token for pagination.

### Use Cases
- Creating a search feature in video apps for users to find specific content.
- Building recommendation systems based on user searches.
- Enhancing content discovery through advanced filtering options.

import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "986bb185-863d-476c-b2b5-d5a86ed963b3" # Action ID for: Execute YouTube Content Search

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "next": "EogDEgVoZWxsbxr-AlNCU0NBUXRaVVVoeldFMW5iRU01UVlJQkMyMUlUMDVPWTFwaWQwUlpnZ0VMWW1VeE1rSkROWEJSVEVXQ0FRdFZNMEZUYWpGTU5sOXpXWUlCQzJaaGVrMVRRMXBuTFcxM2dnRUxaV3hrWldGSlFYWmZkMFdDQVExU1JGbFJTSE5ZVFdkc1F6bEJnZ0VMT0hwRVUybHJRMmc1Tm1PQ0FRc3pOMFU1VjNORWJVUmxaNElCQzJGaFNXcHpPRXN6YjFsdmdnRUxaMmRvUkZKS1ZuaEdlRldDQVF0clN6UXlURnB4VHpCM1FZSUJDME42VHpOaFNXVXdVbkJ6Z2dFTFNVNHdUMk5WZGtkaU5qQ0NBUXRSYTJWbGFGRTRSRjlXVFlJQkMyWk9NVU41Y2pCYVN6bE5nZ0VMZEZac1kwdHdNMkpYU0RpQ0FRdGZSQzFGT1Rsa01XSk1TWUlCQzJoQlUwNVRSSFZOY2pGUmdnRUxkREEzTVZkdE5EVnhWMDAlM0QYgeDoGCILc2VhcmNoLWZlZWQ%3D",
  "sort": "v",
  "type": "v",
  "query": "rick roll",
  "region": "US",
  "duration": "s",
  "features": "li;hd",
  "language": "en",
  "uploadDate": "t"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body (non-JSON): {e.response.text}")
    print("------------------------------------------------")


## Retrieve Video Information
This action provides detailed information about a specific YouTube video using its unique identifier.

### Purpose
It allows developers to gather essential metadata about videos, such as titles, descriptions, and view counts.

### Input Requirements
- **id**: (string) Unique identifier for the video.

### Expected Output
The output includes comprehensive details about the video, making it useful for displaying video information in applications.

### Use Cases
- Integrating video details into a content management system.
- Displaying video metadata in video players or apps.
- Enhancing user experience by providing context around video content.

import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "aa84489a-ab4b-4e1f-941b-b5346430d3a9" # Action ID for: Retrieve Video Information

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "id": "dQw4w9WgXcQ"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body (non-JSON): {e.response.text}")
    print("------------------------------------------------")


## Fetch Related Videos on YouTube
This action retrieves a list of videos related to a specified YouTube video using its unique identifier.

### Purpose
It enables developers to access additional content that complements the main video, enhancing user engagement.

### Input Requirements
- **id**: (string) Unique identifier for the video.
- **next**: (string) Token for pagination.
- **countryCode**: (string) Represents the country for related content.
- **languageCode**: (string) Represents the language for content.

### Expected Output
The output includes a list of related videos, helping users discover more content aligned with their interests.

### Use Cases
- Creating "You might also like" sections in video apps.
- Enhancing playlists with related video suggestions.
- Building recommendation engines for personalized content delivery.

import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "f42e175c-39d6-404a-952d-f64c09d511ad" # Action ID for: Fetch Related Videos on YouTube

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "id": "YQHsXMglC9A",
  "next": "CBQSDRILWVFIc1hNZ2xDOUEYACreAQjQr43tubfzi64BCNi24eOapu-n7AEIgejpz9fcuPajAQjwqMe8v7SEuJ0BCI3CwqDWu4nahAEItNrrwNnAzuQ1CK6-ooCH-Jj5JAik8O-ahq3L1sYBCMb965f10YS4UwiNkaXwtL_gzi4I1vOMu5f7r4HeAQjEuYHvqNfimgwIzvHK75mt1Z27AQjw_7n5yaLZ3_UBCJOq5eCOo-XS_QEIocGSnpeajIsXCN2F2tj65L_4zwEI4KbhwtjP98duCI_C_IbhttbzTAi2gO-y3KbjuZgBCNbN7-m31YCKVmoPd2F0Y2gtbmV4dC1mZWVk",
  "countryCode": "US",
  "languageCode": "en"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body (non-JSON): {e.response.text}")
    print("------------------------------------------------")


## Conclusion
The YouTube Content Search and Info API provides robust capabilities for developers looking to integrate YouTube's rich content into their applications. From fetching trending videos to retrieving detailed comments and metadata, this API simplifies the process of accessing and utilizing YouTube content. By implementing these actions, you can enhance user engagement, improve content discovery, and create a more dynamic experience for your audience. Start by exploring these actions today to unlock the full potential of YouTube content in your applications!