- Use cases
- Comment data for sentiment analysis
Comment data for sentiment analysis
Pull comments with like counts from videos and posts.
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
Failed requests and cached repeats cost 0 credits. Send max_age_days to accept a recent cached copy. See credits and caching.
| Endpoint | Returns | Cost |
|---|---|---|
| YouTube video comments | 1 credit | |
| TikTok video comments | 1 credit | |
| Instagram post comments | 1 credit | |
| Facebook post comments | 1 credit |
Recipe
- Pick the videos or posts.
- Page through the comments.
- Score the text; keep likes as a weight.
1import os2import requests34API = "https://api.socialscrape.dev"5HEADERS = {"x-api-key": os.environ["SOCIALSCRAPE_API_KEY"]}678def get(path, **params):9 res = requests.get(API + path, headers=HEADERS, params=params, timeout=60)10 res.raise_for_status()11 return res.json()["data"]1213# YouTube video comments14comments = get("/v1/youtube/video/comments", url="https://www.youtube.com/watch?v=dQw4w9WgXcQ", sort="top")1516rows = [(c["text"], c["stats"]["likes"]) for c in comments["items"]]17print(len(rows), rows[:3])1const API = "https://api.socialscrape.dev";2const headers = { "x-api-key": process.env.SOCIALSCRAPE_API_KEY! };34async function get(path: string, params: Record<string, string | number | boolean>) {5 const query = new URLSearchParams(Object.entries(params).map(([k, v]) => [k, String(v)]));6 const res = await fetch(`${API}${path}?${query}`, { headers });7 if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);8 return (await res.json()).data;9}1011// YouTube video comments12const comments = await get("/v1/youtube/video/comments", { url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ", sort: "top" });1314const rows = comments.items.map((c: any) => [c.text, c.stats.likes]);15console.log(rows.length, rows.slice(0, 3));Calls use api.socialscrape.dev and return the shapes in the reference.
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.