• Stars
    star
    311
  • Rank 129,421 (Top 3 %)
  • Language
  • Created 10 months ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Reverse-engineering Instagram's Threads private APIs.

How Threads Works

This repository contains my notes and discoveries while reverse-engineering Threads app. Feel free to PR if you've found something new, or to build clients with this info (with credit ofc πŸ˜‰).

Web (threads.net)

The web version of Threads is currently read-only, so not much can be learned about authentication or posting. It uses Meta's Relay GraphQL Client to talk to the backend (threads.net/api/graphql), which seems to be configured to disallow arbitrary queries. This leaves us limited to the existing queries found in the frontend's source:

Note When querying the GraphQL backend, make sure to set an user-agent (seems like anything works here) and set the x-ig-app-id header to 238260118697367.

Get profile data

Doc ID: 23996318473300828

Variables: userID (the user's ID)

curl --request POST \
  --url https://www.threads.net/api/graphql \
  --header 'user-agent: threads-client' \
  --header 'x-ig-app-id: 238260118697367' \
  --header 'content-type: application/x-www-form-urlencoded' \
  --data 'variables={"userID":"314216"}' \
  --data doc_id=23996318473300828

Get profile posts

Doc ID: 6232751443445612

Variables: userID (the user's ID)

curl --request POST \
  --url https://www.threads.net/api/graphql \
  --header 'user-agent: threads-client' \
  --header 'x-ig-app-id: 238260118697367' \
  --header 'content-type: application/x-www-form-urlencoded' \
  --data 'variables={"userID":"314216"}' \
  --data doc_id=6232751443445612

Get profile replies

Doc ID: 6307072669391286

Variables: userID (the user's ID)

curl --request POST \
  --url https://www.threads.net/api/graphql \
  --header 'user-agent: threads-client' \
  --header 'x-ig-app-id: 238260118697367' \
  --header 'content-type: application/x-www-form-urlencoded' \
  --data 'variables={"userID":"314216"}' \
  --data doc_id=6307072669391286

Get a post

Doc ID: 5587632691339264

Variables: postID (the post's ID)

curl --request POST \
  --url https://www.threads.net/api/graphql \
  --header 'user-agent: threads-client' \
  --header 'x-ig-app-id: 238260118697367' \
  --header 'content-type: application/x-www-form-urlencoded' \
  --data 'variables={"postID":"3138977881796614961"}' \
  --data doc_id=5587632691339264

Get a list of users who liked a post

Doc ID: 9360915773983802

Variables: mediaID (the post's ID)

curl --request POST \
  --url https://www.threads.net/api/graphql \
  --header 'user-agent: threads-client' \
  --header 'x-ig-app-id: 238260118697367' \
  --header 'content-type: application/x-www-form-urlencoded' \
  --data 'variables={"mediaID":"3138977881796614961"}' \
  --data doc_id=9360915773983802

Mobile Apps

Authentication

Warning This endpoint currently only works for accounts without 2FA enabled.

The mobile apps use Meta's Bloks framework (originally built for Instagram Lite) for authentication.

The bloks versioning ID for threads is 00ba6fa565c3c707243ad976fa30a071a625f2a3d158d9412091176fe35027d8. Bloks also requires you to provide a device id (of shape ios-RANDOM | android-RANDOM, RANDOM being a random set of 13 chars).

curl --request POST \
  --url 'https://i.instagram.com/api/v1/bloks/apps/com.bloks.www.bloks.caa.login.async.send_login_request/' \
  --header 'user-agent: Barcelona 289.0.0.77.109 Android' \
  --header 'sec-fetch-site: same-origin' \
  --header 'content-type: application/x-www-form-urlencoded; charset=UTF-8' \
  --data 'params={"client_input_params":{"password":"$PASSWORD","contact_point":"$USERNAME","device_id":"$DEVICE_ID"},"server_params":{"credential_type":"password","device_id":"$DEVICE_ID"}}' \
  --data 'bloks_versioning_id=00ba6fa565c3c707243ad976fa30a071a625f2a3d158d9412091176fe35027d8'

This request returns a big JSON payload. Your token will be immediately after the string Bearer IGT:2:, and should be 160 characters long.

Creating a text post

curl --request POST \
  --url 'https://i.instagram.com/api/v1/media/configure_text_only_post/' \
  --header 'content-type: application/x-www-form-urlencoded; charset=UTF-8' \
  --header 'user-agent: Barcelona 289.0.0.77.109 Android' \
  --header 'authorization: Bearer IGT:2:$TOKEN' \
  --header 'sec-fetch-site: same-origin' \
  --data 'signed_body=SIGNATURE.{"publish_mode":"text_post","text_post_app_info":"{\"reply_control\":0}","timezone_offset":"0","source_type":"4","_uid":"$USER_ID","device_id":"$DEVICE_ID","caption":"$POST_TEXT","device":{"manufacturer":"OnePlus","model":"ONEPLUS+A3003","android_version":26,"android_release":"8.1.0"}}'

Misc

How to get a profile's id from their username?

Threads uses the same ID system used by Instagram. The best approach to convert from username to id seems to be requesting the user's instagram page (instagram.com/:username) and manually parsing the response HTML. For other methods, see this StackOverflow question.

More Repositories

1

chatgpt-telegram

Run your own GPTChat Telegram bot, with a single command!
Go
3,868
star
2

plz-cli

Copilot for your terminal
Rust
1,568
star
3

yt-whisper

Using OpenAI's Whisper to automatically generate YouTube subtitles
Python
1,284
star
4

lil-web3

Simple, intentionally-limited versions of web3 protocols & apps.
Solidity
1,166
star
5

auto-commit

A CLI tool that automatically writes commit messages for you.
Rust
1,161
star
6

auto-subtitle

Automatically generate and overlay subtitles for any video.
Python
1,095
star
7

laravel-fastlogin

Allow your users to login with FaceID/TouchID
PHP
962
star
8

browser-agent

A browser AI agent, using GPT-4
Rust
646
star
9

dapp-starter

The template I use to kickstart all my web3 apps.
TypeScript
394
star
10

armchair

A Next.js template with everthing your web3 app needs.
TypeScript
368
star
11

tinyvector

A tiny embedding database in pure Rust.
Rust
333
star
12

chatgpt-discord

Run your own GPTChat Discord bot, with a single command!
Go
287
star
13

commit

Command palette-style Git client for blazing-fast commits.
Rust
240
star
14

mirror-next

A Next.js-powered frontend for your Mirror publication
JavaScript
140
star
15

Tasks

Simple tasks & notes manager written in PHP, jQuery and Bootstrap using a custom flat file database.
PHP
107
star
16

nft-token-drop

A drop-in contract to airdrop all current holders of an NFT with an ERC20 token
Solidity
106
star
17

laravel-web3-login

Allow your users to login with their Ethereum wallet.
PHP
101
star
18

cog-rust

Rust containers for machine learning.
Rust
98
star
19

proof-of-kyc

An NFT that proves you've gone through an identity verification process, powered by Stripe Identity.
TypeScript
86
star
20

whisper-cli-rs

A Whisper CLI, built with Rust.
Rust
82
star
21

clippy-widget

An AI-powered assistant for your company's docs.
TypeScript
76
star
22

threads-api

Reverse-engineered Rust client for Instagram's Threads app.
Rust
74
star
23

refract

A Hacker News style forum, built on the Lens Protocol.
TypeScript
66
star
24

erc721-drop

A simple ERC721 drop implementation, using Forge and Solmate.
Solidity
64
star
25

ray-js

JavaScript
57
star
26

connect4-sol

An optimised Connect4 game implementation on Solidity
Solidity
51
star
27

Activity

A PHP API to log anything anywhere
PHP
48
star
28

support_center

Support center made with Laravel
PHP
47
star
29

better-pest

A better Pest test runner for VS Code
JavaScript
44
star
30

cog-nsfw-filter

Run any image through the Stable Diffusion content filter
Python
43
star
31

laravel-apple-login

Plug-and-play Sign in with Apple for Laravel
PHP
42
star
32

lil-docker

An intentionally-limited Rust implementation of the Docker runtime with no external dependencies.
Rust
41
star
33

nextjs13-connectkit-siwe

Using ConnectKit's SIWE with the Next.js v13 App Router
TypeScript
40
star
34

laravel-multiformat

Multiformat Endpoints in Laravel
PHP
39
star
35

send-to-things

A PWA to add tasks to Things from pretty much anywhere
JavaScript
39
star
36

lil-redis

An intentionally-limited Rust implementation of the Redis server with no external dependencies.
Rust
39
star
37

textos-twitter

Swift
39
star
38

ai-code

copilot, but worse
TypeScript
36
star
39

laravel-fun

A fun package that registers a few routes bots usually search for, and gives them a nice surprise instead.
PHP
36
star
40

zorb-fridge

Zorbs shift when transferred. The Zorb Fridge allows you to freeze them.
Solidity
33
star
41

lens-leaderboard

A leaderboard using 100% public data to rank notable profiles on the Lens Protocol.
TypeScript
32
star
42

lumiere

Web3 video platform, powered by the Lens Protocol.
TypeScript
31
star
43

soulminter-contracts

A barebones contract to easily mint Soulbound NFTs
Solidity
30
star
44

php-evm

"lol. lmao" - m1guelpf.eth
PHP
29
star
45

roam-app

An iOS app for Roam Research
Swift
27
star
46

lil-http-rs

A Rust web framework with no external dependencies
Rust
26
star
47

dyson

Your self-hosted ML model interface
Rust
26
star
48

flysystem

A filesystem abstraction layer for Rust.
Rust
26
star
49

dollar-auction.sol

A dollar auction implementation in Solidity.
Solidity
24
star
50

amnesia

An expressive Rust library for interacting with a cache.
Rust
24
star
51

solserve

An experimental Solidity-based web framework
TypeScript
23
star
52

ensemble

A Laravel-inspired ORM for Rust
Rust
23
star
53

wagmipet-frontend

An on-chain tamagotchi-inspired game, with metratransactions and social login.
TypeScript
22
star
54

repair-json

Repair incomplete JSON (e.g. from streaming APIs or AI models) so it can be parsed as it's received.
Rust
21
star
55

ens-contracts-blindrun

For Solidity practice, I tried to rebuild the base ENS contracts from the EIP-137.
Solidity
20
star
56

wallet-activity

User-friendly Ethereum transaction descriptions.
TypeScript
19
star
57

soulminter

One-click mint for Soulbound NFTs on Ethereum, Optimism & Polygon.
TypeScript
19
star
58

wagmipet-contracts

Solidity
19
star
59

dapp-browser

A simple, ENS-powered browser for Ethereum dApps
JavaScript
19
star
60

silhouette

A simple dependency injection library for Rust
Rust
19
star
61

mute.guru

Take back your twitter feed, by instantly muting all engagement farmers.
TypeScript
18
star
62

ghost-heroku

Deploy Ghost to Heroku (with storage)
JavaScript
18
star
63

necromint

An ERC721 for resurrecting the dead.
Solidity
17
star
64

walletconnect-extension

JavaScript
16
star
65

website-theme

The Ghost theme that powers my website
JavaScript
16
star
66

obs-now-playing

Let your listeners know what music you're playing right now by showing it on screen at all times!
JavaScript
16
star
67

epicenter

Simple sync/async event dispatcher for Rust
Rust
13
star
68

lens-embeds

One-click embeds for all your links posts, mirrors & comments.
TypeScript
12
star
69

indigo

A simple interface for speaking with AI assistants. Inspired by OpenAI's DevDay Keynote.
Swift
12
star
70

m1guelpf

11
star
71

weekday-nft

An experiment in generative NFTs that tells you the current day of the week.
JavaScript
11
star
72

rainbow-bridge-ios

An iOS Safari extension that redirects MetaMask calls to Rainbow.
Swift
11
star
73

LicAPI

A PHP API to manage license info
PHP
11
star
74

cog-whisper

OpenAI Whisper as a Cog model
Python
11
star
75

formtato

A lil web3 form for Ana's potato comissions
TypeScript
10
star
76

redeez-rs

A simplified general-purpose queueing system for Rust apps.
Rust
10
star
77

things-newtab

Your Things tasks on every tab
Vue
9
star
78

native-collection

Adding Collection functions to the PHP array scalar type
PHP
9
star
79

clippy

AI-powered assistant for your company's docs
Rust
9
star
80

php-ghost-api

A PHP API client for the Ghost v2 Content API
PHP
8
star
81

proof-of-love

Refactoring of a simple smart contract for Leah
Solidity
8
star
82

laravel-ssl

A Laravel package to enforce HTTPS
PHP
7
star
83

nouns-dataset

A HuggingFace text-to-image dataset for Nouns
TypeScript
7
star
84

ens-delegatoor

A lil website that shows who you've delegated your $ENS to.
TypeScript
7
star
85

laragit

A Laravel interface for managing Github notifications.
PHP
7
star
86

aranet-rs

Read air quality data from an Aranet4 device in Rust
Rust
7
star
87

laravel-feature

Feature toggling for Laravel
PHP
6
star
88

pingcrm-rs

A demo application to illustrate an Axum + Inertia.js workflow.
Rust
6
star
89

readme-with-video

An example of a repo with a video on its README
6
star
90

book-story

An original book-reading experience powered by AMP Stories
HTML
6
star
91

wc-playground

Playing around with WalletConnect v2
TypeScript
5
star
92

eloquent-immutable

Enforce table immutability using Laravel Eloquent
PHP
5
star
93

lens-garden

Links only your Lens followers can access.
TypeScript
5
star
94

netlify-mix

Use Netlify as a CDN for your Laravel Mix assets
PHP
5
star
95

php-fly-api

A PHP Client for the Fly.io API
PHP
5
star
96

lens-hotlink

Lens Protocol links that open with your preferred frontend
TypeScript
5
star
97

twitch-og

Better Twitch embeds for social media sharing
JavaScript
5
star
98

cog-pop2piano

Python
5
star
99

spotify

PHP
4
star
100

axum-signed-urls

Signed URL middleware for Axum, using extractors.
Rust
4
star