The job
Comments are the audience talking. Fetch them with likes, author and time, then run your classifier or model over the text column.
Endpoints
| Endpoint | Returns | Cost |
|---|---|---|
GET /v1/youtube/video/comments | YouTube video comments | 1 credit |
GET /v1/tiktok/video/comments | TikTok video comments | 1 credit |
GET /v1/instagram/post/comments | Instagram post comments | 1 credit |
GET /v1/facebook/post/comments | Facebook post comments | 1 credit |
Failed requests and cached repeats cost 0 credits. Send max_age_days to accept a recent cached copy. See credits and caching.
Recipe
- Pick the videos or posts.
- Page through the comments.
- Score the text; keep likes as a weight.
Preview
The API is in early access. Calls use
api.socialscrape.io and return the shapes in the reference.Python
import os
import requests
API = "https://api.socialscrape.io"
HEADERS = {"x-api-key": os.environ["SOCIALSCRAPE_API_KEY"]}
def get(path, **params):
res = requests.get(API + path, headers=HEADERS, params=params, timeout=60)
res.raise_for_status()
return res.json()["data"]
# YouTube video comments
comments = get("/v1/youtube/video/comments", url="https://www.youtube.com/watch?v=dQw4w9WgXcQ", sort="top")
rows = [(c["text"], c["stats"]["likes"]) for c in comments["items"]]
print(len(rows), rows[:3])TypeScript
const API = "https://api.socialscrape.io";
const headers = { "x-api-key": process.env.SOCIALSCRAPE_API_KEY! };
async function get(path: string, params: Record<string, string | number | boolean>) {
const query = new URLSearchParams(Object.entries(params).map(([k, v]) => [k, String(v)]));
const res = await fetch(`${API}${path}?${query}`, { headers });
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
return (await res.json()).data;
}
// YouTube video comments
const comments = await get("/v1/youtube/video/comments", { url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ", sort: "top" });
const rows = comments.items.map((c: any) => [c.text, c.stats.likes]);
console.log(rows.length, rows.slice(0, 3));Good to know
A page is a slice of the thread, not all of it. Page until has_more is false if you need the whole thread.