Get an API key; the examples use
api.socialscrape.dev.Set up
You need Python 3 and the requests package.
1python -m venv .venv2source .venv/bin/activate3pip install requests4export SOCIALSCRAPE_API_KEY=ss_live_...The script
Save as scrape.py and run python scrape.py. It calls GET /v1/instagram/post/comments.
1import csv2import os3import time45import requests67URL = "https://api.socialscrape.dev/v1/instagram/post/comments"8HEADERS = {"x-api-key": os.environ["SOCIALSCRAPE_API_KEY"]}9PARAMS = {10 "url": "https://www.instagram.com/reel/DfF3eqGSKKc/",11}12MAX_ITEMS = 100131415def pick(obj, *path):16 """Follow a path through nested dicts; None if any step is missing or null."""17 for key in path:18 obj = obj.get(key) if isinstance(obj, dict) else None19 return obj202122def get(params):23 """One request. Failures cost nothing; retry the ones the API marks retryable."""24 for attempt in range(3):25 body = requests.get(URL, headers=HEADERS, params=params, timeout=60).json()26 if body["ok"]:27 return body28 err = body["error"]29 if not err["retryable"] or attempt == 2:30 raise RuntimeError(f'{err["code"]}: {err["message"]}')31 time.sleep(2**attempt)323334items = []35params = dict(PARAMS)36while len(items) < MAX_ITEMS:37 body = get(params)38 items += body["data"]["items"]39 if not body["has_more"]:40 break41 params["cursor"] = body["cursor"]42items = items[:MAX_ITEMS]4344with open("out.csv", "w", newline="", encoding="utf-8") as f:45 writer = csv.writer(f)46 writer.writerow(["text", "id", "stats.likes"])47 for item in items:48 writer.writerow([pick(item, "text"), pick(item, "id"), pick(item, "stats", "likes")])4950print(f"saved {len(items)} rows to out.csv, credits left: {body['credits_remaining']}")How it works
get()sends one request and retries the failures the API marksretryable. A failed request costs nothing.- The loop follows
cursoruntilhas_moreis false or 100 items are collected. Each page costs its own price. pick()reads nested fields and givesNoneinstead of crashing when the platform returnednull.- Rows go to
out.csv, one column per field.
What you get back
These fields come from a recorded sample. The full field list is on the endpoint page.
SampleFields in the script
1{2 "text": "❤️❤️",3 "id": "18125925943986939",4 "stats": {5 "likes": 06 }7}The short version
Without paging, saving or retries, the request is this.
1import os2import requests34params = {5 "url": "https://www.instagram.com/reel/DfF3eqGSKKc/",6}7res = requests.get(8 "https://api.socialscrape.dev/v1/instagram/post/comments",9 headers={"x-api-key": os.environ["SOCIALSCRAPE_API_KEY"]},10 params=params,11 timeout=60,12)13body = res.json()1415if body["ok"]:16 print(body["data"])17else:18 print(body["error"]["code"], body["error"]["message"])With the SDK
The Python client does the retries and the paging for you: see the SDKs.
1from socialscrape import SocialScrape23client = SocialScrape() # reads SOCIALSCRAPE_API_KEY45for item in client.paginate(client.instagram.post_comments, url="https://www.instagram.com/reel/DfF3eqGSKKc/", max_items=100):6 print(item["text"])What it costs
1 credit. A failed request costs nothing. Add max_age_days to reuse a cached result for 0 credits. Results are kept 30 days.
Next
- The same request in nine languages.
- Instagram post comments API: sample response and every parameter.
- The JavaScript version.
- All Instagram endpoints.