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
Extract channel-videos data from YouTube
Learn how to scrape YouTube channel videos using Java. This comprehensive guide will walk you through the entire process, from setup to implementation.
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.
Make sure you have the following installed:
Apache HttpClient is a robust HTTP client for Java
mvn dependency:add -DgroupId=org.apache.httpcomponents -DartifactId=httpclient -Dversion=4.5.13
Now let's make a request to the YouTube API using Java. Replace YOUR_API_KEY
with your actual API key.
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;
import java.util.Map;
import java.util.stream.Collectors;
public class Scraper {
private static final String API_KEY = "YOUR_API_KEY";
private static final String BASE_URL = "https://api.scrapecreators.com";
private static final String ENDPOINT_PATH = "/v1/youtube/channel-videos";
public static void main(String[] args) {
try {
String result = scrape();
System.out.println("Response: " + result);
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
public static String scrape() throws Exception {
HttpClient client = HttpClient.newHttpClient();
// Build query parameters
Map<String, String> params = Map.of(
"channelId", "UC-9-kyTW8ZkZNDHQJ6FgpwQ",
"handle", "ThePatMcAfeeShow",
"sort", "latest",
"continuationToken", "4qmFsgKrCBIYVUNkRkpXVWE0M3NtUm00SXBIQnB",
"includeExtras", "false"
);
String queryString = params.entrySet().stream()
.map(entry -> entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8))
.collect(Collectors.joining("&"));
String url = BASE_URL + ENDPOINT_PATH + "?" + queryString;
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("x-api-key", API_KEY)
.header("Content-Type", "application/json")
.GET()
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 200) {
return response.body();
} else {
throw new RuntimeException("HTTP " + response.statusCode() + ": " + response.body());
}
}
}
This endpoint accepts the following parameters:
channelId
Optional(string)YouTube channel ID
Example: UC-9-kyTW8ZkZNDHQJ6FgpwQ
handle
Optional(string)YouTube channel handle
Example: ThePatMcAfeeShow
sort
Optional(select)Sort by latest or popular
Example: latest
continuationToken
Optional(string)Continuation token to get more videos. Get 'continuationToken' from previous response.
Example: 4qmFsgKrCBIYVUNkRkpXVWE0M3NtUm00SXBIQnB
includeExtras
Optional(string)This will get you the like + comment count and the description. To get the full details of the video, use the /v1/youtube/video endpoint. This will slow down the response slightly.
Example: false
Execute your script to test the API connection. You should see a JSON response with YouTube channel videos data.
✅ Success: You should receive a structured JSON response containing the requested data.
Here's an example of the JSON response you'll receive:
{
"videos": [
{
"type": "video",
"id": "5EWaxmWgQMI",
"url": "https://www.youtube.com/watch?v=5EWaxmWgQMI",
"title": "Russell Wilson Hopes To Finish Career As A Steeler, Reflects On NFL Career With Pat McAfee",
"description": "Welcome to The Pat McAfee Show LIVE from Noon-3PM EST Mon-Fri. You can also find us live on ESPN, ESPN+, & TikTok!\n\nBecome a #McAfeeMafia member! https://www.youtube.com/channel/UCxcTeAKWJca6XyJ37_...",
"thumbnail": "https://i.ytimg.com/vi/5EWaxmWgQMI/hqdefault.jpg?sqp=-oaymwEnCNACELwBSFryq4qpAxkIARUAAIhCGAHYAQHiAQoIGBACGAY4AUAB&rs=AOn4CLBZIBEJGcYDrduIZJpaSmYHcIHJ6g",
"channel": {
"title": "",
"thumbnail": null
},
"viewCountText": "110,447 views",
"viewCountInt": 110447,
"publishedTimeText": "9 days ago",
"publishedTime": "2025-01-23T22:48:53.914Z",
"lengthText": "37:25",
"lengthSeconds": 2245,
"badges": []
}
],
"continuationToken": "4qmFsgLlFhIYV...."
}
Check that your response includes the expected fields:
videos
(object)continuationToken
(string)Implement comprehensive error handling and retry logic for failed requests. Log errors properly for debugging.
Cache responses when possible to reduce API calls and improve performance. Consider data freshness requirements.
Never expose your API key in client-side code. Use environment variables and secure key management practices.
When scraping multiple channel videos, consider batching requests to maximize throughput while staying within rate limits.
Use asynchronous processing in Java to handle multiple requests concurrently and improve overall performance.
Analyze YouTube channel videos to understand market trends, competitor analysis, and audience insights.
Track performance metrics, engagement rates, and content trends across YouTube channel videos.
Identify potential customers and business opportunities throughYouTube data analysis.
Check your API key is correct and properly formatted in the x-api-key header.
You ran out of credits and need to buy more.
The resource might not exist or be private.
Temporary server issue. Implement retry logic with exponential backoff.
ScrapeCreators offers 100 free API calls to get started. After that, pricing starts at $10 for 5k requests with volume discounts available.
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.
There is no rate limit! So you can scrape as fast as you want!
All API responses are returned in JSON format, making it easy to integrate with any programming language or application.
Yes! This tutorial focuses on core Java HTTP concepts that work with any framework. The API calls remain the same regardless of your specific Java setup.
For large datasets, implement pagination, use streaming responses where available, and consider storing data in a database for efficient querying.
Get started with 100 free API calls. No credit card required.