Tutorial · YouTube

📱 Kotlin Step-by-step

How to scrape YouTube shorts
with Kotlin.

Extract shorts data from YouTube. Real code, real responses, real production patterns — paste it into your project and ship.

Overview

Learn how to scrape YouTube shorts using Kotlin. This comprehensive guide will walk you through the entire process, from setup to implementation.

What You'll Learn

  • • Setting up your development environment
  • • Installing the required HTTP client
  • • Authenticating with the ScrapeCreators API
  • • Making requests to YouTube
  • • Handling responses and errors
  • • Best practices for production use

What You'll Get

  • • Access to shorts data
  • • JSON formatted responses
  • • Real-time data access
  • • Scalable solution
  • • Error handling patterns
  • • Performance optimization tips

Prerequisites

1. API Key

First, you'll need a ScrapeCreators API key to authenticate your requests.

Sign up at app.scrapecreators.com to get your free API key with 100 requests.

2. Development Environment

Make sure you have the following installed:

  • Kotlin and its dependencies
  • • A code editor (VS Code, Sublime, etc.)
  • • Basic understanding of API requests
  • • Command line interface access

Step 1: Install HTTP Client

OkHttp is an HTTP client for Kotlin/Java

gradle
implementation "com.squareup.okhttp3:okhttp:4.9.3"

Step 2: API Implementation

Now let's make a request to the YouTube API using Kotlin. Replace YOUR_API_KEY with your actual API key.

Kotlin
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
import java.net.URI
import java.net.URLEncoder
import java.nio.charset.StandardCharsets

class Scraper {
    companion object {
        private const val API_KEY = "YOUR_API_KEY"
        private const val BASE_URL = "https://api.scrapecreators.com"
        private const val ENDPOINT_PATH = "/v1/youtube/channel/shorts"
        
        @JvmStatic
        fun main(args: Array<String>) {
            try {
                val result = scrape()
                println("Response: $result")
            } catch (e: Exception) {
                println("Error: ${e.message}")
            }
        }
        
        fun scrape(): String {
            val client = HttpClient.newHttpClient()
            
            // Build query parameters
            val params = mapOf(
                "handle" to "starterstory",
                "channelId" to "UC-9-kyTW8ZkZNDHQJ6FgpwQ",
                "sort" to "newest",
                "continuationToken" to "4qmFsgKrCBIYVUNkRkpXVWE0M3NtUm00SXBIQnB"
            )
            
            val queryString = params.entries.joinToString("&") { (key, value) ->
                "${key}=${URLEncoder.encode(value, StandardCharsets.UTF_8)}"
            }
            
            val url = "${BASE_URL}${ENDPOINT_PATH}?${queryString}"
            
            val request = HttpRequest.newBuilder()
                .uri(URI.create(url))
                .header("x-api-key", API_KEY)
                .header("Accept", "application/json")
                .GET()
                .build()
            
            val response = client.send(request, HttpResponse.BodyHandlers.ofString())
            
            if (response.statusCode() == 200) {
                return response.body()
            } else {
                throw RuntimeException("HTTP ${response.statusCode()}: ${response.body()}")
            }
        }
    }
}

Step 3: Testing Your Code

API Parameters

This endpoint accepts the following parameters:

handleOptional(string)

Can pass channelId or handle

Example: starterstory

channelIdOptional(string)

Can pass channelId or handle

Example: UC-9-kyTW8ZkZNDHQJ6FgpwQ

sortOptional(select)

Sort by newest or popular

Example: newest

continuationTokenOptional(string)

Continuation token to get more videos. Get 'continuationToken' from previous response.

Example: 4qmFsgKrCBIYVUNkRkpXVWE0M3NtUm00SXBIQnB

Run Your Code

Execute your script to test the API connection. You should see a JSON response with YouTube shorts data.

✅ Success: You should receive a structured JSON response containing the requested data.

Expected Response

Here's an example of the JSON response you'll receive:

Sample Response
{
  "success": true,
  "credits_remaining": 49998970118,
  "videos": [],
  "channels": [],
  "playlists": [],
  "shorts": [
    {
      "type": "short",
      "id": "VREVC0wXPfs",
      "url": "https://www.youtube.com/watch?v=VREVC0wXPfs",
      "title": "This idea validation formula has made him $500K from iOS apps",
      "thumbnail": "https://img.youtube.com/vi/VREVC0wXPfs/maxresdefault.jpg",
      "viewCountText": "17,066",
      "viewCountInt": 17066,
      "description": "Most founders think their app isn’t selling because of market conditions.\n\nIt’s not.\n\nThis founder sold multiple apps and noticed the same pattern every time: Great products but broken deals.\n\nNot because the app was bad but because founders overcomplicate operations and chase the highest price instead of the fastest close.",
      "commentCountText": "2",
      "commentCountInt": 2,
      "likeCountInt": 495,
      "likeCountText": "495",
      "publishDate": "2026-04-22T10:44:35-07:00",
      "genre": "People & Blogs",
      "durationMs": 37000,
      "durationFormatted": "00:00:37"
    },
    {
      "type": "short",
      "id": "LUTxdXW4TUI",
      "url": "https://www.youtube.com/watch?v=LUTxdXW4TUI",
      "title": "$30M founder reveals the ideas he’d bet on again if he had to start over",
      "thumbnail": "https://img.youtube.com/vi/LUTxdXW4TUI/maxresdefault.jpg",
      "viewCountText": "18,917",
      "viewCountInt": 18917,
      "description": "$30M SaaS founder reveals 3 business ideas with massive potential.\n\nHe doesn’t chase “new ideas.”\n\nHe studies what’s already working… then adds a unique twist no one else thought of.\n\nIt’s all about:\n\nSpotting gaps competitors ignore\nMaking it ridiculously easy for customers to say yes\nExecuting better and faster than anyone else\n\nMost people overcomplicate. He keeps it simple… and profitable.",
      "commentCountText": "11",
      "commentCountInt": 11,
      "likeCountInt": 712,
      "likeCountText": "712",
      "publishDate": "2026-03-28T11:25:20-07:00",
      "genre": "People & Blogs",
      "durationMs": 50000,
      "durationFormatted": "00:00:50"
    },
    {
      "type": "short",
      "id": "1YGz9bkG7z0",
      "url": "https://www.youtube.com/watch?v=1YGz9bkG7z0",
      "title": "Founder of 2 profitable SaaS products shares his entire tech stack",
      "thumbnail": "https://img.youtube.com/vi/1YGz9bkG7z0/maxresdefault.jpg",
      "viewCountText": "16,393",
      "viewCountInt": 16393,
      "description": "He got nearly 1 million website visitors** without spending a single dollar on ads.\n\nMost builders think marketing means ads, cold emails, or posting on social media every day.\n\nBut this developer grew a SaaS to $13K MRR and another one to $6K/month before selling without these things.",
      "commentCountText": "4",
      "commentCountInt": 4,
      "likeCountInt": 516,
      "likeCountText": "516",
      "publishDate": "2026-03-24T09:18:13-07:00",
      "genre": "People & Blogs",
      "durationMs": 51000,
      "durationFormatted": "00:00:51"
    },
    {
      "type": "short",
      "id": "19ZP3japTsE",
      "url": "https://www.youtube.com/watch?v=19ZP3japTsE",
      "title": "Founder breaks down his 5 apps making $700K/month 🤯",
      "thumbnail": "https://img.youtube.com/vi/19ZP3japTsE/maxresdefault.jpg",
      "viewCountText": "11,923",
      "viewCountInt": 11923,
      "description": "Most founders dream about one successful app.\nThis guy built five.\n\nNot viral luck.\nNot overnight success.\nJust systems, playbooks, and ruthless execution.",
      "commentCountText": "12",
      "commentCountInt": 12,
      "likeCountInt": 498,
      "likeCountText": "498",
      "publishDate": "2026-03-23T12:35:18-07:00",
      "genre": "People & Blogs",
      "durationMs": 75000,
      "durationFormatted": "00:01:15"
    },
    {
      "type": "short",
      "id": "8PW-9Zr_W5g",
      "url": "https://www.youtube.com/watch?v=8PW-9Zr_W5g",
      "title": "He built 28 apps. They make $10K/month. Same tech stack every time.",
      "thumbnail": "https://img.youtube.com/vi/8PW-9Zr_W5g/maxresdefault.jpg",
      "viewCountText": "67,291",
      "viewCountInt": 67291,
      "description": "I asked this dev making $10K/month from 28 apps… here’s his tech stack 😳\n\nHe went from $200/month → $10K/month in 8 months.",
      "commentCountText": "11",
      "commentCountInt": 11,
      "likeCountInt": 1733,
      "likeCountText": "1733",
      "publishDate": "2026-03-14T17:03:28-07:00",
      "genre": "People & Blogs",
      "durationMs": 35000,
      "durationFormatted": "00:00:35"
    }
  ],
  "shelves": [],
  "lives": [],
  "continuationToken": "4qmFsgK7DBIY....."
}

Verify Response Structure

Check that your response includes the expected fields:

  • success(boolean)
  • credits_remaining(number)
  • videos(object)
  • channels(object)
  • playlists(object)
  • ... and 4 more fields

Best Practices

1

Error Handling

Implement comprehensive error handling and retry logic for failed requests. Log errors properly for debugging.

2

Caching

Cache responses when possible to reduce API calls and improve performance. Consider data freshness requirements.

3

Security

Never expose your API key in client-side code. Use environment variables and secure key management practices.

Performance Tips

Batch Requests

When scraping multiple shorts, consider batching requests to maximize throughput while staying within rate limits.

Async Processing

Use asynchronous processing in Kotlin to handle multiple requests concurrently and improve overall performance.

Common Use Cases

Market Research

Analyze YouTube shorts to understand market trends, competitor analysis, and audience insights.

Content Analytics

Track performance metrics, engagement rates, and content trends across YouTube shorts.

Lead Generation

Identify potential customers and business opportunities throughYouTube data analysis.

Troubleshooting

Common Errors

401 Unauthorized

Check your API key is correct and properly formatted in the x-api-key header.

402 Payment Required

You ran out of credits and need to buy more.

404 Not Found

The resource might not exist or be private.

500 Server Error

Temporary server issue. Implement retry logic with exponential backoff.

Frequently Asked Questions

How much does it cost to scrape YouTube shorts?

ScrapeCreators offers 100 free API calls to get started. After that, pricing starts at $10 for 5k requests with volume discounts available.

Is it legal to scrape YouTube data?

Scraping publicly available data is fair game, and we only collect public data. So anything that you can see in an incognito browser is what we collect.

How fast can I scrape YouTube shorts?

There is no rate limit! So you can scrape as fast as you want!

What data format does the API return?

All API responses are returned in JSON format, making it easy to integrate with any programming language or application.

Can I use this with other Kotlin frameworks?

Yes! This tutorial focuses on core Kotlin HTTP concepts that work with any framework. The API calls remain the same regardless of your specific Kotlin setup.

How do I handle large datasets?

For large datasets, implement pagination, use streaming responses where available, and consider storing data in a database for efficient querying.

Related Tutorials

Ready to ship?

Get the API key. Run the code.

100 free API calls. No credit card. Same endpoint, same response shape.

Same endpoint, different language

Pick another stack.