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/profile.
1import json2import os3import time45import requests67URL = "https://api.socialscrape.dev/v1/instagram/profile"8HEADERS = {"x-api-key": os.environ["SOCIALSCRAPE_API_KEY"]}9PARAMS = {10 "handle": "nasa",11}121314def pick(obj, *path):15 """Follow a path through nested dicts; None if any step is missing or null."""16 for key in path:17 obj = obj.get(key) if isinstance(obj, dict) else None18 return obj192021def get(params):22 """One request. Failures cost nothing; retry the ones the API marks retryable."""23 for attempt in range(3):24 body = requests.get(URL, headers=HEADERS, params=params, timeout=60).json()25 if body["ok"]:26 return body27 err = body["error"]28 if not err["retryable"] or attempt == 2:29 raise RuntimeError(f'{err["code"]}: {err["message"]}')30 time.sleep(2**attempt)313233body = get(PARAMS)34data = body["data"]3536with open("out.json", "w", encoding="utf-8") as f:37 json.dump(data, f, ensure_ascii=False, indent=2)3839print("name:", str(pick(data, "name"))[:200])40print("handle:", str(pick(data, "handle"))[:200])41print("stats.followers:", str(pick(data, "stats", "followers"))[:200])42print(f"saved out.json, 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 result is one object in
data. pick()reads nested fields and givesNoneinstead of crashing when the platform returnednull.- The whole object goes to
out.jsonand a few fields are printed.
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 "name": "NASA",3 "handle": "nasa",4 "stats": {5 "followers": 1043607466 }7}The short version
Without paging, saving or retries, the request is this.
1import os2import requests34params = {5 "handle": "nasa",6}7res = requests.get(8 "https://api.socialscrape.dev/v1/instagram/profile",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 for you: see the SDKs.
1from socialscrape import SocialScrape23client = SocialScrape() # reads SOCIALSCRAPE_API_KEY45res = client.instagram.profile(handle="nasa")6print(res.data)7print(res.credits_charged, res.credits_remaining)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 profile API: sample response and every parameter.
- The JavaScript version.
- All Instagram endpoints.