api.socialscrape.dev.Before you start
- An API key, sent in the
x-api-keyheader. Keep it on your server. - For this endpoint you send nothing beyond your key. The Instagram trending reels page lists every parameter.
Step 1: Send the request
GET /v1/instagram/reels/trending. Pick your language; each one reads the key from SOCIALSCRAPE_API_KEY.
1curl "https://api.socialscrape.dev/v1/instagram/reels/trending" \2 -H "x-api-key: $SOCIALSCRAPE_API_KEY"1import os2import requests34params = {}5res = requests.get(6 "https://api.socialscrape.dev/v1/instagram/reels/trending",7 headers={"x-api-key": os.environ["SOCIALSCRAPE_API_KEY"]},8 params=params,9 timeout=60,10)11body = res.json()1213if body["ok"]:14 print(body["data"])15else:16 print(body["error"]["code"], body["error"]["message"])1const url = new URL("https://api.socialscrape.dev/v1/instagram/reels/trending");2url.search = new URLSearchParams({}).toString();3const res = await fetch(url, {4 headers: { "x-api-key": process.env.SOCIALSCRAPE_API_KEY },5});6const body = await res.json();78if (body.ok) {9 console.log(body.data);10} else {11 console.error(body.error.code, body.error.message);12}1const url = new URL("https://api.socialscrape.dev/v1/instagram/reels/trending");2url.search = new URLSearchParams({}).toString();3const res = await fetch(url, {4 headers: { "x-api-key": process.env.SOCIALSCRAPE_API_KEY! },5});6const body = await res.json();78if (body.ok) {9 console.log(body.data);10} else {11 console.error(body.error.code, body.error.message);12}1package main23import (4 "fmt"5 "io"6 "net/http"7 "os"8)910func main() {11 req, _ := http.NewRequest("GET", "https://api.socialscrape.dev/v1/instagram/reels/trending", nil)12 req.Header.Set("x-api-key", os.Getenv("SOCIALSCRAPE_API_KEY"))13 res, err := http.DefaultClient.Do(req)14 if err != nil {15 panic(err)16 }17 defer res.Body.Close()18 body, _ := io.ReadAll(res.Body)19 fmt.Println(res.StatusCode, string(body))20}1<?php2$ch = curl_init('https://api.socialscrape.dev/v1/instagram/reels/trending');3curl_setopt_array($ch, [4 CURLOPT_RETURNTRANSFER => true,5 CURLOPT_HTTPHEADER => ["x-api-key: " . getenv("SOCIALSCRAPE_API_KEY")],6]);7$body = json_decode(curl_exec($ch), true);8curl_close($ch);910if ($body["ok"]) {11 print_r($body["data"]);12} else {13 echo $body["error"]["code"], " ", $body["error"]["message"], "\n";14}1require "net/http"2require "json"34uri = URI('https://api.socialscrape.dev/v1/instagram/reels/trending')5req = Net::HTTP::Get.new(uri)6req["x-api-key"] = ENV.fetch("SOCIALSCRAPE_API_KEY")7res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }8body = JSON.parse(res.body)910if body["ok"]11 puts body["data"]12else13 puts body["error"]["code"], body["error"]["message"]14end1import java.net.URI;2import java.net.http.HttpClient;3import java.net.http.HttpRequest;4import java.net.http.HttpResponse;56public class Main {7 public static void main(String[] args) throws Exception {8 HttpRequest req = HttpRequest.newBuilder()9 .uri(URI.create("https://api.socialscrape.dev/v1/instagram/reels/trending"))10 .header("x-api-key", System.getenv("SOCIALSCRAPE_API_KEY"))11 .GET()12 .build();13 HttpResponse<String> res = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());14 System.out.println(res.statusCode() + " " + res.body());15 }16}1using System;2using System.Net.Http;34var client = new HttpClient();5client.DefaultRequestHeaders.Add("x-api-key", Environment.GetEnvironmentVariable("SOCIALSCRAPE_API_KEY"));6var res = await client.GetAsync("https://api.socialscrape.dev/v1/instagram/reels/trending");7Console.WriteLine((int)res.StatusCode);8Console.WriteLine(await res.Content.ReadAsStringAsync());Step 2: Read the response
Results are in data.items. Here is what one item gives you, from a recorded sample.
1for item in body["data"]["items"]:2 print(item["text"])3 print(item["id"])4 print(item["stats"]["likes"])1for (const item of body.data.items) {2 console.log(item.text);3 console.log(item.id);4 console.log(item.stats.likes);5}1{2 "text": "Welp #cool",3 "id": "DfBK2blPXvQ",4 "stats": {5 "likes": 11997656 }7}A field the platform does not give comes back as null. The full field list is on the endpoint page.
Step 3: Get the next page
Send the same request with the cursor you got back, until has_more is false. Each page costs its own price.
1import os2import requests34url = "https://api.socialscrape.dev/v1/instagram/reels/trending"5headers = {"x-api-key": os.environ["SOCIALSCRAPE_API_KEY"]}6params = {}78items = []9while len(items) < 100:10 body = requests.get(url, headers=headers, params=params, timeout=60).json()11 if not body["ok"]:12 raise RuntimeError(body["error"]["code"])13 items += body["data"]["items"]14 if not body["has_more"]:15 break16 params["cursor"] = body["cursor"]1718print(len(items), "items")1const url = new URL("https://api.socialscrape.dev/v1/instagram/reels/trending");2const headers = { "x-api-key": process.env.SOCIALSCRAPE_API_KEY };34const items = [];5while (items.length < 100) {6 const body = await (await fetch(url, { headers })).json();7 if (!body.ok) throw new Error(body.error.code);8 items.push(...body.data.items);9 if (!body.has_more) break;10 url.searchParams.set("cursor", body.cursor);11}1213console.log(items.length, "items");Step 4: Handle errors
Check ok, then branch on error.code and error.retryable, never on the message.
1body = res.json()2if not body["ok"]:3 err = body["error"]4 if err["retryable"]:5 ... # wait a moment and send the same request again6 else:7 raise RuntimeError(f'{err["code"]}: {err["message"]}')1const body = await res.json();2if (!body.ok) {3 const { code, message, retryable } = body.error;4 if (retryable) {5 // wait a moment and send the same request again6 } else {7 throw new Error(`${code}: ${message}`);8 }9}| Code | HTTP | Retry | Meaning |
|---|---|---|---|
not_found | 404 | no | The platform says this profile, post or item does not exist. |
Other errors, such as unauthorized or rate_limited, are on the errors page.
With the SDK
The Python and TypeScript clients wrap all of this: typed errors, retries, and cursor paging. Install them with pip install socialscrape-sdk or npm install socialscrape.
1from socialscrape import SocialScrape23client = SocialScrape() # reads SOCIALSCRAPE_API_KEY45for item in client.paginate(client.instagram.reels_trending, max_items=100):6 print(item["text"])1import { SocialScrape } from "socialscrape";23const client = new SocialScrape(); // reads SOCIALSCRAPE_API_KEY45for await (const item of client.paginate(client.instagram.reelsTrending, {}, { maxItems: 100 })) {6 console.log(item.text);7}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 1 day.
Next
- Instagram trending reels API: sample response and every parameter.
- A full Python script and a full JavaScript script for this endpoint.
- All Instagram endpoints.