Unofficial, Reverse-Engineered Node.js/TypeScript client for Meta's Threads.
β¨ The App Registry is officially live! We invite you to explore it on our website at threads.junho.io.
Modify threads-web-ui/data/apps.ts to add your projects!
import { ThreadsAPI } from 'threads-api';
// or in Deno π¦:
// import ThreadsAPI from "npm:threads-api";
const main = async () => {
const threadsAPI = new ThreadsAPI();
const username = '_junhoyeo';
// π€ Details for a specific user
const userID = await threadsAPI.getUserIDfromUsername(username);
if (!userID) {
return;
}
const user = await threadsAPI.getUserProfile(userID);
console.log(JSON.stringify(user));
const posts = await threadsAPI.getUserProfileThreads(userID);
console.log(JSON.stringify(posts));
const replies = await threadsAPI.getUserProfileReplies(userID);
console.log(JSON.stringify(replies));
// π Details for a specific thread
const postID = threadsAPI.getPostIDfromURL(
'https://www.threads.net/t/CuX_UYABrr7/?igshid=MzRlODBiNWFlZA==',
);
// or use `threadsAPI.getPostIDfromThreadID('CuX_UYABrr7')`
if (!postID) {
return;
}
const post = await threadsAPI.getThreads(postID);
console.log(JSON.stringify(post.containing_thread));
console.log(JSON.stringify(post.reply_threads));
const likers = await threadsAPI.getThreadLikers(postID);
console.log(JSON.stringify(likers));
};
main();
const { items: threads, next_max_id: cursor } = await threadsAPI.getTimeline();
console.log(JSON.stringify(threads));
const { threads, next_max_id: cursor } = await threadsAPI.getUserProfileThreadsLoggedIn(userID);
console.log(JSON.stringify(threads));
const { threads, next_max_id: cursor } = await threadsAPI.getUserProfileRepliesLoggedIn(userID);
console.log(JSON.stringify(threads));
const { users, next_max_id: cursor } = await threadsAPI.getUserFollowers(userID);
console.log(JSON.stringify(users));
const { users, next_max_id: cursor } = await threadsAPI.getUserFollowings(userID);
console.log(JSON.stringify(users));
Note
From v1.4.0, you can also calllogin
to update yourtoken
anduserID
(for current credentials). Or you can just use the methods below, and they'll take care of the authentication automatically (e.g. if it's the first time you're using those).
import { ThreadsAPI } from 'threads-api';
const main = async () => {
const threadsAPI = new ThreadsAPI({
username: '_junhoyeo', // Your username
password: 'PASSWORD', // Your password
});
await threadsAPI.publish({
text: 'π€ Hello World',
});
};
main();
π‘ TIP: Use the
url
field inThreadsAPIPublishOptions
to render Link Attachments(link previews).
await threadsAPI.publish({
text: 'π€ Threads with Reply Control',
replyControl: 'accounts_you_follow', // 'everyone' | 'accounts_you_follow' | 'mentioned_only'
});
await threadsAPI.publish({
text: 'π€ Threads with Link Attachment',
attachment: {
url: 'https://github.com/junhoyeo/threads-api',
},
});
await threadsAPI.publish({
text: 'π€ Threads with Image',
attachment: {
image: 'https://github.com/junhoyeo/threads-api/raw/main/.github/cover.jpg',
},
});
ThreadsAPI.Image
in attachment.image
can also be type of ThreadsAPI.ExternalImage
or ThreadsAPI.RawImage
.
Info
The term "sidecar" is what Threads uses to represent a group of images and/or videos that share the same post.
await threadsAPI.publish({
text: 'π€ Threads with Sidecar',
attachment: {
sidecar: [
'https://github.com/junhoyeo/threads-api/raw/main/.github/cover.jpg',
'https://github.com/junhoyeo/threads-api/raw/main/.github/cover.jpg',
{ path: './zuck.jpg' }, // ThreadsAPI.ExternalImage
{ type: '.jpg', data: Buffer.from(β¦) }, // ThreadsAPI.RawImage
],
},
});
const parentURL = 'https://www.threads.net/t/CugF-EjhQ3r';
const parentPostID = threadsAPI.getPostIDfromURL(parentURL); // or use `getPostIDfromThreadID`
await threadsAPI.publish({
text: 'π€ Beep',
link: 'https://github.com/junhoyeo/threads-api',
parentPostID: parentPostID,
});
const threadURL = 'https://www.threads.net/t/CuqbBI8h19H';
const postIDToQuote = threadsAPI.getPostIDfromURL(threadURL); // or use `getPostIDfromThreadID`
await threadsAPI.publish({
text: 'π€ Quote a Thread',
quotedPostID: postIDToQuote,
});
const threadURL = 'https://www.threads.net/t/CugK35fh6u2';
const postIDToLike = threadsAPI.getPostIDfromURL(threadURL); // or use `getPostIDfromThreadID`
// π‘ Uses current credentials
await threadsAPI.like(postIDToLike);
await threadsAPI.unlike(postIDToLike);
const userIDToFollow = await threadsAPI.getUserIDfromUsername('junhoyeo');
// π‘ Uses current credentials
await threadsAPI.follow(userIDToFollow);
await threadsAPI.unfollow(userIDToFollow);
const threadURL = 'https://www.threads.net/t/CugK35fh6u2';
const postIDToRepost = threadsAPI.getPostIDfromURL(threadURL); // or use `getPostIDfromThreadID`
// π‘ Uses current credentials
await threadsAPI.repost(postIDToRepost);
await threadsAPI.unrepost(postIDToRepost);
const postID = await threadsAPI.publish({
text: 'π€ This message will self-destruct in 5 seconds.',
});
await new Promise((resolve) => setTimeout(resolve, 5_000));
await threadsAPI.delete(postID);
image
and url
options in publish
image
and url
options in publish
await threadsAPI.publish({
text: 'π€ Threads with Image',
image: 'https://github.com/junhoyeo/threads-api/raw/main/.github/cover.jpg',
});
await threadsAPI.publish({
text: 'π€ Threads with Link Attachment',
url: 'https://github.com/junhoyeo/threads-api',
});
Single string
argument in publish
string
argument in publish
import { ThreadsAPI } from 'threads-api';
const main = async () => {
const threadsAPI = new ThreadsAPI({
username: 'jamel.hammoud', // Your username
password: 'PASSWORD', // Your password
});
await threadsAPI.publish('π€ Hello World');
};
main();
You can also provide custom deviceID
(Default is android-${(Math.random() * 1e24).toString(36)}
).
const deviceID = `android-${(Math.random() * 1e24).toString(36)}`;
const threadsAPI = new ThreadsAPI({
username: 'jamel.hammoud',
password: 'PASSWORD',
deviceID,
});
yarn add threads-api
# or with npm
npm install threads-api
# or with pnpm
pnpm install threads-api
// or in Deno π¦
import ThreadsAPI from 'npm:threads-api';
const threadsAPI = new ThreadsAPI.ThreadsAPI({});
- β
Read public data
- β
Fetch UserID(
314216
) via username(zuck
) - β Read timeline feed
- β Read User Profile Info
- β
Read list of User Threads
- β With Pagination (If auth provided)
- β
Read list of User Replies
- β With Pagination (If auth provided)
- β
Fetch PostID(
3140957200974444958
) via ThreadID(CuW6-7KyXme
) or PostURL(https://www.threads.net/t/CuW6-7KyXme
) - β Read Threads via PostID
- β Read Likers in Thread via PostID
- β Read User Followers
- β Read User Followings
- β
Fetch UserID(
- β
Write data (i.e. write automated Threads)
- β
Create new Thread with text
- β Make link previews to get shown
- β Create new Thread with a single image
- β Create new Thread with multiple images
- β Reply to existing Thread
- β Quote Thread
- β Delete Thread
- β
Create new Thread with text
- β
Friendships
- β Follow User
- β Unfollow User
- β
Interactions
- β Like Thread
- β Unlike Thread
- π΄ββ οΈ Restructure the project as a monorepo
- π΄ββ Add Demo App with Next.js
- Use components in π΄ββ οΈ junhoyeo/react-threads
- Make it better
- Package with Electron
- π΄ββ οΈ Cool CLI App to run Threads in the Terminal
- π΄ββ Add Demo App with Next.js
Add yours by just opening an pull request!
Embed Static Threads in your React/Next.js application. UI components for Meta's Threads. Powered by junhoyeo/threads-api.
Warning
Vercel Deployment is currently sometimes unstable. π΄ββ οΈ
To use the threads-api
command line interface, run the following command:
threads-api
command line interface, run the following command:$ npx threads-api --help
Usage: threads-api [command] [options]
Options:
-v, --version output the current version
-h, --help display help for command
Commands:
help display help for command
getUserIDfromUsername|userid|uid|id <username> det user ID from username
getUserProfile|userprofile|uprof|up <username> <userId> [stringify] get user profile
getUserProfileThreads|uthreads|ut <username> <userId> [stringify] get user profile threads
getUserProfileReplies|userreplies|ureplies|ur <username> <userId> [stringify] get user profile replies
getPostIDfromURL|postid|pid|p <postURL> get post ID from URL
getThreads|threads|t <postId> [stringify] get threads
getThreadLikers|threadlikers|likers|l <postId> [stringify] get thread likers
π€ threads-projects
: Unleashing the power of Meta's Threads.net platform with insightful bots and efficient workflows
MIT Β© Junho Yeo
If you find this project intriguing, please consider starring it(β) or following me on GitHub (I wouldn't say Threads). I code 24/7 and ship mind-breaking things on a regular basis, so your support definitely won't be in vain.