PHP

How to Get a YouTube Channel ID from a URL in PHP

CK CK 3788 
Created at
Updated at  
1,015 0 0

If you have a YouTube channel URL like:

https://www.youtube.com/@%EC%B6%94%EC%B6%94%EB%A3%A8%EC%A3%BC%EC%B6%98

…and you need the Channel ID (the one that starts with UC...), YouTube doesn’t include it directly in handle-based URLs. The easiest and most reliable way is to use the YouTube Data API v3.

 

Step 1: Get a YouTube Data API Key

The YouTube Data API is free for up to 10,000 requests per day, which is more than enough for most projects.

  1. Go to Google Cloud Console
    https://console.cloud.google.com/ 
  2. Create a Project
    • Click the project dropdown → New Project
    • Name it (e.g., YouTubeAPIProject) → Create
  3. Enable YouTube Data API v3
    • Go to the API page
    • Click Enable
  4. Create an API Key
    • In the left menu: APIs & Services → Credentials
    • Click Create Credentials → API key
    • Copy the key shown
  5. (Optional) Restrict the Key
    • Click your new API key
    • Under API Restrictions, choose YouTube Data API v3
    • Under Application Restrictions, limit by IP or HTTP referrer

 

Step 2: PHP Script to Get Channel ID from a Handle

<?php function getYouTubeChannelIdFromHandle($handle, $apiKey) {
    $url = "https://www.googleapis.com/youtube/v3/channels?part=id&forHandle=" . urlencode($handle) . "&key=" . $apiKey;
    $json = file_get_contents($url);
    $data = json_decode($json, true);

    return $data['items'][0]['id'] ?? null;
}

$apiKey = "YOUR_API_KEY";  // Replace with your real key $handle = "@추추루주춘"; // Your YouTube handle

$channelId = getYouTubeChannelIdFromHandle($handle, $apiKey);

echo "Channel ID: " . $channelId;

 

Step 3: Test Your Key

Visit this URL in your browser (replace YOUR_API_KEY):

https://www.googleapis.com/youtube/v3/channels?part=id&forHandle=@추추루주춘&key=YOUR_API_KEY

If successful, you’ll get:

{
  "items": [
    {
      "id": "UCxxxxxxxxxxxxxxxx"
    }
  ]
} 

 

💡 Notes

  • API usage is free within the quota (10,000 lookups/day).
  • No scraping is required, so this method is stable.
  • Works with handles, custom URLs, and direct channel URLs.
Tags Google Cloud Console YouTube API Facebook X
Comments 0
Similar posts
  1. Creating a Service Account via Google Cloud Console (UI)
    1,055
  1. When you Postgresql Module is not able to open connection : Doubt your libpq version
    472
  2. Building a MCP server in PHP
    627
  3. PHP 7 vs PHP 8
    1,240
  4. Upgrading PHP 7.4 to PHP 8.1 in CentOS 7
    642
  5. gRPC Server with PHP
    499
  6. PHP Code to Fetch current Coinbase Assets (Balances)
    438
  7. PHP Code to Fetch PEPE coin pricing based in USD from Coinbase
    362
  8. Google Single Sign-On implementation with PHP
    1,367
  9. PHP Superglobal Variables do not require additional syntax to access it
    2,618
  10. Run Python Code with Virtual Environment in PHP
    671
  11. PHP Simplified Operators
    317
  12. PHP Heredoc (aka Nowdoc)
    428
  13. PHP Post Processing by disconnecting HTTP connection and continuing the remaining logics
    1,800
  14. WordPress Remote Posting with PHP
    1,675
  15. Google BigQuery Example to converted Nested FIelds in JSON
    458
  16. Verifying Apple In-App Purchase validation receipt with PHP
    1,779
Recently updated
  1. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    27
  2. Why SPF and DKIM Are Essential for Linux Email Servers?
    24
  3. How do I create animated background for Google Meet?
    19,735
  4. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    217
  5. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    86
  6. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    153
  7. Array of arguments passed to script in PHP
    85
  8. Invalid Auction Storms in Ad Tech
    93
  9. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    198
  10. The Two Clocks of Ad Server Architecture
    63
  11. Frequency Cap Architecture Overview
    509
  12. Collecting Proof-of-Play from 100,000 Screens
    141
  13. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    280
  14. What is RedisVL?
    105
  15. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    224
  16. TPU & GPU Cluster Management Tools
    234
  17. The Concept of Scaffolding in AI Agents
    222
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    576
  19. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    253
  20. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    328
  21. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    198
  22. Machine Learning: Training vs. Ranking
    213
  23. The Continuous Learning Machine: Designing a Loop That Actually Turns
    217
  24. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    189
  25. Designing a Data Curation System Around a Vector Database
    215
  26. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    229
  27. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    649
  28. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    185
  29. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    207
  30. Understanding Data Lineage
    252