Tutorials

How to scrape Instagram and TikTok: tutorials

Code for every endpoint in six languages, full scripts for common jobs, and setup guides for n8n, Make, Zapier and Google Sheets. Filter by platform and language below; every sample pages with the cursor and retries on 429.

Short answer. To scrape public Instagram or TikTok data, call an API that returns it as JSON, follow pagination.next_cursor through lists, and write each page to a file. With HandleHaul that is one X-Api-Key header and no logins. Every sample below was run against the documented responses before it went on this page.

Start with your language or tool

Language guide

Instagram and TikTok API in Python

Two ways to call HandleHaul from Python: a 60-line client on requests that you own, or the official handlehaul package (sync and async).

Language guide

Instagram and TikTok API in Node.js

Call HandleHaul from Node.js 18 or newer with the built-in fetch, or install the typed handlehaul package from npm, which also ships a CLI.

Language guide

Instagram and TikTok API in PHP

One class, PHP 8 and the curl extension: no Composer package needed.

Language guide

Instagram and TikTok API in Go

A standard-library Go client with generic Page[T] and One[T] types: decode the fields you need into structs, page with a callback, and get a typed APIError for anything else.

Language guide

Instagram and TikTok API in Ruby

A standard-library Ruby client: Net::HTTP, JSON and an Enumerator for cursor paging, so .first(100) or .take_while stops calling when you have enough.

Language guide

Instagram and TikTok API with cURL

Every route works from a terminal: one header, JSON back.

No code

Instagram and TikTok data in Google Sheets

Paste one Apps Script file, add your key as a script property, and a HandleHaul menu fills follower counts for a list of Instagram accounts and views, likes and saves for a list of TikTok videos.

No code

Instagram and TikTok data in n8n

n8n’s HTTP Request node can page through HandleHaul lists on its own: set one header credential, point it at a route, and tell it where the next cursor is.

No code

Instagram and TikTok data in Make

Make’s HTTP “Make a request” module calls any HandleHaul route.

No code

Instagram and TikTok data in Zapier

Two ways to call HandleHaul from a Zap: the Webhooks by Zapier GET action for a single request, or a Code by Zapier step when you want retries and only the fields you need.

Full scripts for common jobs

One complete program per job, from input list to CSV, in Python and in Node.js.

Instagram · Python

Export Instagram followers to CSV

Page through a public account’s followers, newest first, 25 a page, and stop after N pages.

Instagram · Node.js

Export Instagram followers to CSV

Page through a public account’s followers, newest first, 25 a page, and stop after N pages.

Instagram · Python

Bulk Instagram profiles to CSV

A list of usernames in, one CSV row each out: counts, bio, category, verified, id.

Instagram · Node.js

Bulk Instagram profiles to CSV

A list of usernames in, one CSV row each out: counts, bio, category, verified, id.

Instagram · Python

Export Instagram comments to CSV

Every comment on a public post, top or newest first, with replies where there are any.

Instagram · Node.js

Export Instagram comments to CSV

Every comment on a public post, top or newest first, with replies where there are any.

TikTok · Python

TikTok transcripts to text and SRT

A list of video links in, one .txt per video out, plus .srt subtitles from the timed segments.

TikTok · Node.js

TikTok transcripts to text and SRT

A list of video links in, one .txt per video out, plus .srt subtitles from the timed segments.

TikTok · Python

TikTok video views and likes to CSV

A list of video links in, views, likes, comments, shares and saves out, with a timestamp per row.

TikTok · Node.js

TikTok video views and likes to CSV

A list of video links in, views, likes, comments, shares and saves out, with a timestamp per row.

TikTok · Python

Export TikTok comments to CSV

Every comment on a video, about 20 a page, de-duplicated by id, replies optional.

TikTok · Node.js

Export TikTok comments to CSV

Every comment on a video, about 20 a page, de-duplicated by id, replies optional.

Every endpoint, in every language

One page per API route: why you would call it, the parameters, code in cURL, Python, Node.js, PHP, Go and Ruby (plus both SDKs), a sample response and what it costs.

Instagram API

Profiles

  • ProfileGET /v1/instagram/users/{user}Profile by username or id
  • Account detailsGET /v1/instagram/users/{user}/account-detailsWhen the account joined, its country and username changes
  • Similar accountsGET /v1/instagram/users/{user}/relatedAccounts similar to this one

Followers & following

  • FollowersGET /v1/instagram/users/{user}/followersFollowers, newest first
  • FollowingGET /v1/instagram/users/{user}/followingFollowing, newest first

Posts & reels

  • PostsGET /v1/instagram/users/{user}/postsRecent posts
  • ReelsGET /v1/instagram/users/{user}/reelsReels of an account, newest first (or most viewed)
  • Tagged postsGET /v1/instagram/users/{user}/taggedPosts the account is tagged in
  • RepostsGET /v1/instagram/users/{user}/repostsPosts the account reposted
  • Post or reelGET /v1/instagram/posts/{post}One post or reel by shortcode, id or URL
  • Post stats (batch)GET /v1/instagram/posts/statsLike, comment and view counts for up to 20 posts in one call

Comments & likes

  • CommentsGET /v1/instagram/posts/{post}/commentsComments on a post
  • Comment repliesGET /v1/instagram/comments/{comment}/repliesReplies to a comment
  • Post likersGET /v1/instagram/posts/{post}/likersAccounts that liked a post
  • Comment likersGET /v1/instagram/comments/{comment}/likersAccounts that liked a comment

Stories & highlights

  • StoriesGET /v1/instagram/users/{user}/storiesLive stories (last 24 hours)
  • Story by idGET /v1/instagram/stories/{story}One story by id
  • HighlightsGET /v1/instagram/users/{user}/highlightsStory highlights of an account
  • Highlight storiesGET /v1/instagram/highlights/{highlight}The stories inside a highlight

Hashtags

  • Search hashtagsGET /v1/instagram/search/hashtagsFind hashtags
  • HashtagGET /v1/instagram/hashtags/{tag}A hashtag and its post count
  • Hashtag postsGET /v1/instagram/hashtags/{tag}/postsTop posts for a hashtag

Locations

  • Search placesGET /v1/instagram/search/placesFind places by name or near a point
  • PlaceGET /v1/instagram/places/{place}A place: name, category, address, contact
  • Place postsGET /v1/instagram/places/{place}/postsTop or recent posts tagged at a place

Audio

  • Search audioGET /v1/instagram/search/audioFind songs and original audio
  • Trending audioGET /v1/instagram/audio/trendingTrending audio on Reels
  • AudioGET /v1/instagram/audio/{audio}A song or original audio
  • Reels using audioGET /v1/instagram/audio/{audio}/reelsReels that use an audio
  • Search accountsGET /v1/instagram/search/usersSearch accounts by name
  • URL resolverGET /v1/instagram/resolveInstagram URL → type and ids (free)

TikTok API

Profiles

  • ProfileGET /v1/tiktok/users/{user}TikTok profile: bio, verified and private flags, follower, following, like and video counts
  • Suggested accountsGET /v1/tiktok/users/{user}/suggestedAccounts TikTok suggests alongside this one (one page)

Followers & following

  • FollowersGET /v1/tiktok/users/{user}/followersFollowers of a TikTok account
  • FollowingGET /v1/tiktok/users/{user}/followingAccounts a TikTok account follows

Videos

  • PostsGET /v1/tiktok/users/{user}/postsVideos and photo posts of a TikTok account, newest first
  • RepostsGET /v1/tiktok/users/{user}/repostsVideos a TikTok account reposted
  • Liked videosGET /v1/tiktok/users/{user}/likedVideos a TikTok account liked (when its liked list is public)
  • PlaylistsGET /v1/tiktok/users/{user}/playlistsPlaylists of a TikTok account
  • StoriesGET /v1/tiktok/users/{user}/storiesLive stories of a TikTok account
  • Video or photo postGET /v1/tiktok/posts/{post}One TikTok video or photo post by id or URL

Comments

  • CommentsGET /v1/tiktok/posts/{post}/commentsComments on a TikTok post
  • Comment repliesGET /v1/tiktok/comments/{comment}/repliesReplies to a TikTok comment

Transcripts

  • TranscriptGET /v1/tiktok/posts/{post}/transcriptTranscript of a TikTok video from its auto-captions

Music

  • SoundGET /v1/tiktok/music/{music}A TikTok sound: title, artist, duration and how many posts use it
  • Posts using a soundGET /v1/tiktok/music/{music}/postsPosts that use a TikTok sound

Hashtags

  • HashtagGET /v1/tiktok/hashtags/{tag}A TikTok hashtag with its post and view counts
  • Hashtag postsGET /v1/tiktok/hashtags/{tag}/postsPosts under a TikTok hashtag
  • SearchGET /v1/tiktok/searchSearch TikTok: top videos, users, videos, photo posts, live streams or sounds

What every script does

  • Reads the key from HANDLEHAUL_API_KEY. Never hard-code it, and never ship it in a browser or mobile app.
  • Pages with the cursor. Lists come one page per call with pagination.next_cursor and has_more. Cursors are opaque: pass them back unchanged. A page limit caps the spend.
  • Retries on 429. Over your speed limit the API answers 429 with Retry-After; the script waits and tries again. 429 answers are not charged. 502, 503 and 504 are retried with a growing wait.
  • Stops on anything else. A wrong key, no credits or a private account ends the run with the error code and message. Rows already fetched stay in the file. In list-of-items scripts, a missing account or video is noted in the CSV and the run goes on.
  • Writes a clean CSV. Cells with commas, quotes or line breaks are quoted (RFC 4180), and the file opens in Excel with emoji intact.

Public data only: the scripts never log in, and private accounts answer an error (free). Read the acceptable use policy before you collect data about people, and check the data protection rules that apply to you. Full reference: API docs.

Scraping tutorials: questions

How do I scrape Instagram?
Pick the data you need (profiles, followers, posts, comments), call the matching API endpoint with an API key, follow pagination.next_cursor to page through lists, and write the rows to CSV or a database. The tutorials above are complete scripts for the common jobs. Public accounts only.
How do I scrape TikTok?
The same way: one call per video for counts or transcripts, cursor paging for comments and follower lists. No browser automation and no request signing on your side: the API returns TikTok’s public data as JSON.
Do I need an Instagram or TikTok account?
No. The scripts never log in to either platform. They need only a HandleHaul API key, and they read public data only.
Which languages are covered?
Every endpoint has code in cURL, Python, Node.js, PHP, Go and Ruby, plus the official Python and Node SDKs (pip install handlehaul, npm install handlehaul). The job scripts are in Python and Node.js. Without code, use n8n, Make, Zapier or Google Sheets.
Is the code tested?
Every sample is syntax-checked (py_compile, node --check, php -l, gofmt and go vet, ruby -c, bash -n) and run against a local mock that serves the documented responses, including a 429 with Retry-After, cursor paging and a private-account error. It is not run against the live API with a key.
What does running a tutorial cost?
1 credit per successful call, $1.40 to $0.80 per 1,000 calls. 1,000 Instagram followers take 40 calls ($0.056 to $0.032); 1,000 TikTok comments take 50 ($0.070 to $0.040). Failed calls are free, and a sandbox key runs every script on sample data at no cost.

Run the scripts on your own data

One key for Instagram and TikTok. $1.40 to $0.80 per 1,000 calls; failed calls are free.

Want to test first? Sandbox keys are free and unlimited, with sample data in the live schema.