1. Use cases
  2. 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.

EndpointReturnsCost
YouTube video comments1 credit
TikTok video comments1 credit
Instagram post comments1 credit
Facebook post comments1 credit

Recipe

  1. Pick the videos or posts.
  2. Page through the comments.
  3. 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])

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.

Related