api.socialscrape.dev.Before you start
- An API key, sent in the
x-api-keyheader. Keep it on your server. - For this endpoint you send one of
urlorid. The YouTube video transcript page lists every parameter.
Step 1: Send the request
GET /v1/youtube/video/transcript. Pick your language; each one reads the key from SOCIALSCRAPE_API_KEY.
1curl -G "https://api.socialscrape.dev/v1/youtube/video/transcript" \2 -H "x-api-key: $SOCIALSCRAPE_API_KEY" \3 --data-urlencode 'id=dQw4w9WgXcQ' \4 --data-urlencode 'language=de'1import os2import requests34params = {5 "id": "dQw4w9WgXcQ",6 "language": "de",7}8res = requests.get(9 "https://api.socialscrape.dev/v1/youtube/video/transcript",10 headers={"x-api-key": os.environ["SOCIALSCRAPE_API_KEY"]},11 params=params,12 timeout=60,13)14body = res.json()1516if body["ok"]:17 print(body["data"])18else:19 print(body["error"]["code"], body["error"]["message"])1const url = new URL("https://api.socialscrape.dev/v1/youtube/video/transcript");2url.search = new URLSearchParams({3 id: "dQw4w9WgXcQ",4 language: "de",5}).toString();6const res = await fetch(url, {7 headers: { "x-api-key": process.env.SOCIALSCRAPE_API_KEY },8});9const body = await res.json();1011if (body.ok) {12 console.log(body.data);13} else {14 console.error(body.error.code, body.error.message);15}1const url = new URL("https://api.socialscrape.dev/v1/youtube/video/transcript");2url.search = new URLSearchParams({3 id: "dQw4w9WgXcQ",4 language: "de",5}).toString();6const res = await fetch(url, {7 headers: { "x-api-key": process.env.SOCIALSCRAPE_API_KEY! },8});9const body = await res.json();1011if (body.ok) {12 console.log(body.data);13} else {14 console.error(body.error.code, body.error.message);15}1package main23import (4 "fmt"5 "io"6 "net/http"7 "net/url"8 "os"9)1011func main() {12 q := url.Values{}13 q.Set("id", "dQw4w9WgXcQ")14 q.Set("language", "de")15 req, _ := http.NewRequest("GET", "https://api.socialscrape.dev/v1/youtube/video/transcript" + "?" + q.Encode(), nil)16 req.Header.Set("x-api-key", os.Getenv("SOCIALSCRAPE_API_KEY"))17 res, err := http.DefaultClient.Do(req)18 if err != nil {19 panic(err)20 }21 defer res.Body.Close()22 body, _ := io.ReadAll(res.Body)23 fmt.Println(res.StatusCode, string(body))24}1<?php2$query = http_build_query([3 'id' => 'dQw4w9WgXcQ',4 'language' => 'de',5]);6$ch = curl_init('https://api.socialscrape.dev/v1/youtube/video/transcript' . "?" . $query);7curl_setopt_array($ch, [8 CURLOPT_RETURNTRANSFER => true,9 CURLOPT_HTTPHEADER => ["x-api-key: " . getenv("SOCIALSCRAPE_API_KEY")],10]);11$body = json_decode(curl_exec($ch), true);12curl_close($ch);1314if ($body["ok"]) {15 print_r($body["data"]);16} else {17 echo $body["error"]["code"], " ", $body["error"]["message"], "\n";18}1require "net/http"2require "json"34uri = URI('https://api.socialscrape.dev/v1/youtube/video/transcript')5uri.query = URI.encode_www_form('id' => 'dQw4w9WgXcQ', 'language' => 'de')6req = Net::HTTP::Get.new(uri)7req["x-api-key"] = ENV.fetch("SOCIALSCRAPE_API_KEY")8res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }9body = JSON.parse(res.body)1011if body["ok"]12 puts body["data"]13else14 puts body["error"]["code"], body["error"]["message"]15end1import java.net.URI;2import java.net.URLEncoder;3import java.net.http.HttpClient;4import java.net.http.HttpRequest;5import java.net.http.HttpResponse;6import java.nio.charset.StandardCharsets;78public class Main {9 public static void main(String[] args) throws Exception {10 String query = "id=" + URLEncoder.encode("dQw4w9WgXcQ", StandardCharsets.UTF_8) + "&language=" + URLEncoder.encode("de", StandardCharsets.UTF_8);11 HttpRequest req = HttpRequest.newBuilder()12 .uri(URI.create("https://api.socialscrape.dev/v1/youtube/video/transcript" + "?" + query))13 .header("x-api-key", System.getenv("SOCIALSCRAPE_API_KEY"))14 .GET()15 .build();16 HttpResponse<String> res = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());17 System.out.println(res.statusCode() + " " + res.body());18 }19}1using System;2using System.Net.Http;34var client = new HttpClient();5client.DefaultRequestHeaders.Add("x-api-key", Environment.GetEnvironmentVariable("SOCIALSCRAPE_API_KEY"));6var query = string.Join("&", new[] {7 "id=" + Uri.EscapeDataString("dQw4w9WgXcQ"),8 "language=" + Uri.EscapeDataString("de"),9});10var res = await client.GetAsync("https://api.socialscrape.dev/v1/youtube/video/transcript" + "?" + query);11Console.WriteLine((int)res.StatusCode);12Console.WriteLine(await res.Content.ReadAsStringAsync());Step 2: Read the response
The result is in data. Here is what the object gives you, from a recorded sample.
1print(body["data"]["text"])1console.log(body.data.text);1{2 "text": "Uns beiden ist die Liebe nicht fremd Du kennst die Regeln genau wie ich Für mich zählst nur du Das kriegst du sonst von keinem hier Ich will dir sagen, wie i..."3}A field the platform does not give comes back as null. The full field list is on the endpoint page.
Step 3: Handle errors
Check ok, then branch on error.code and error.retryable, never on the message.
1body = res.json()2if not body["ok"]:3 err = body["error"]4 if err["retryable"]:5 ... # wait a moment and send the same request again6 else:7 raise RuntimeError(f'{err["code"]}: {err["message"]}')1const body = await res.json();2if (!body.ok) {3 const { code, message, retryable } = body.error;4 if (retryable) {5 // wait a moment and send the same request again6 } else {7 throw new Error(`${code}: ${message}`);8 }9}| Code | HTTP | Retry | Meaning |
|---|---|---|---|
invalid_params | 400 | no | A parameter is missing, unknown or has the wrong type. |
unsupported_url | 400 | no | The URL is not one this endpoint accepts (wrong platform or form). |
not_found | 404 | no | The platform says this profile, post or item does not exist. |
transcript_unavailable | 404 | no | No captions exist and AI transcription is not possible for this media. |
Other errors, such as unauthorized or rate_limited, are on the errors page.
With the SDK
The Python and TypeScript clients wrap all of this: typed errors, retries. Install them with pip install socialscrape-sdk or npm install socialscrape.
1from socialscrape import SocialScrape23client = SocialScrape() # reads SOCIALSCRAPE_API_KEY45res = client.youtube.video_transcript(id="dQw4w9WgXcQ", language="de")6print(res.data)7print(res.credits_charged, res.credits_remaining)1import { SocialScrape } from "socialscrape";23const client = new SocialScrape(); // reads SOCIALSCRAPE_API_KEY45const res = await client.youtube.videoTranscript({ id: "dQw4w9WgXcQ", language: "de" });6console.log(res.data);7console.log(res.credits_charged, res.credits_remaining);What it costs
1 credit for captions; AI transcription 1 up to 2 minutes, then 5 per started minute of the whole video. A failed request costs nothing. Add max_age_days to reuse a cached result for 0 credits. Results are kept 30 days.
Next
- YouTube video transcript API: sample response and every parameter.
- A full Python script and a full JavaScript script for this endpoint.
- All YouTube endpoints.