junhoyeo / threads-api Goto Github PK
View Code? Open in Web Editor NEWUnofficial, Reverse-Engineered Node.js/TypeScript client for Meta's Threads. Web UI Included.
Home Page: https://threads.junho.io
License: MIT License
Unofficial, Reverse-Engineered Node.js/TypeScript client for Meta's Threads. Web UI Included.
Home Page: https://threads.junho.io
License: MIT License
Hi,
I am copying these calls into a Java client.
How can we obtain the 'x-fb-lsd' token?
Thanks
threads-api
and create symlink in rootYou're doing great work, can you also add support for single thread search using the link: https://www.threads.net/t/CuVvNbmtr06
Here's the code:
const main = async () => {
const accountUsername = "my_username";
const accountPassword = "my_password";
const threadsApi = new ThreadsAPI({username: accountUsername, password: accountPassword})
const success = await threadsApi.publish("Publishing test!");
console.log(`Status: ${success ? 'Success' : 'Failure'}`);
}
main();
As you can see vary basic example.
And here's an error:
UnhandledPromiseRejectionWarning: TypeError: i.sent(...).data.split(...)[1].split(...)[0].replaceAll is not a function
at d.<anonymous> (/home/getrasa/work/threads/threads-auto-ts/node_modules/threads-api/build/threads-api.js:1:9832)
at /home/getrasa/work/threads/threads-auto-ts/node_modules/threads-api/build/threads-api.js:1:1769
at Object.next (/home/getrasa/work/threads/threads-auto-ts/node_modules/threads-api/build/threads-api.js:1:1874)
at o (/home/getrasa/work/threads/threads-auto-ts/node_modules/threads-api/build/threads-api.js:1:350)
at i (/home/getrasa/work/threads/threads-auto-ts/node_modules/threads-api/build/threads-api.js:1:547)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:28058) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:28058) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Hi! I was also in the process of reverse engineering the Threads API when I stumbled upon your repository. Do you plan on documenting your reverse engineering process? I think it would be very valuable! :)
Looks like calling getPostIDfromURL
from Vercel is getting 429 responses.
GetPostID
However, getThreads
is working fine
GetThreads
Perhaps we need to find the API endpoint for getPostIDfromURL
instead of just calling the website? ๐ค
I imagine the Threads team modified how auth works but now the response I get back is
{"layout":{"bloks_payload":{"data":[],"props":[{"id":"-6917714003244327204","name":"ttrc_instance_id"},{"id":"2231046902902521263","name":"override_login_success_action"}],"error_attribution":{"logging_id":"{\"callsite\":\"{\\\"product\\\":\\\"bloks_caa_login\\\",\\\"feature\\\":\\\"com.bloks.www.bloks.caa.login.async.send_login_request\\\",\\\"integration\\\":\\\"bloks_screen\\\",\\\"oncall\\\":\\\"caa_login\\\"}\",\"push_phase\":\"C3\",\"version\":1,\"request_id\":\"ART4gxH0zzo2SJiUV7jumw3\"}"},"tree":{"ใ":{"#":" (bk.action.core.TakeLast, (bk.action.dialog.OpenDialog, (bk.action.bloks.InflateSync, (bk.action.map.Make, (bk.action.array.Make, \"\\u35e7\"), (bk.action.array.Make, (bk.action.map.Make, (bk.action.array.Make, \"(\", \"#\", \"$\", \"*\"), (bk.action.array.Make, \"Unable to log in\", \"An unexpected error occurred. Please try logging in again.\", (bk.action.map.Make, (bk.action.array.Make, \"\\u35e8\"), (bk.action.array.Make, (bk.action.map.Make, (bk.action.array.Make, \"$\", \"#\"), (bk.action.array.Make, \"OK\", (bk.action.core.FuncConst, (bk.action.logging.LogEvent, \"caa_login_client_events_ig\", \"\", (bk.action.map.Make, (bk.action.array.Make, \"core\", \"login_params\"), (bk.action.array.Make, (bk.action.map.Make, (bk.action.array.Make, \"event\", \"event_category\", \"event_flow\", \"event_request_id\", \"event_step\", \"is_dark_mode\", \"exception_code\", \"exception_message\", \"exception_type\", \"extra_client_data\", \"logged_out_identifier\", \"logged_in_identifier\", \"waterfall_id\"), (bk.action.array.Make, \"login_error_dialog_ok_clicked\", \"login_home_page_interaction\", \"login_manual\", \"4b019ef2-c3e2-4b03-8ecc-25379e661f80\", \"home_page\", (ig.action.IsDarkModeEnabled), (bk.action.i32.Const, 0), \"\", \"\", (bk.action.map.Make, (bk.action.array.Make), (bk.action.array.Make)), \"\", \"\", \"62fd26b6-35c9-4d1c-9482-d7b398a9309c\")), (bk.action.map.Make, (bk.action.array.Make), (bk.action.array.Make)))))))))), (bk.action.i32.Const, 0)))))), (bk.action.bloks.InflateSync, (bk.action.map.Make, (bk.action.array.Make, \"\\u35f0\"), (bk.action.array.Make, (bk.action.map.Make, (bk.action.array.Make), (bk.action.array.Make)))))), (bk.action.map.Make, (bk.action.array.Make, \"should_dismiss_loading\"), (bk.action.array.Make, (bk.action.bool.Const, true))))"}}}},"status":"ok"}
With email / passwords that did use to work and so it fails at this split since the format doesn't match what's expected
Maybe publishWithImage should be combined with publish and support multiple images in the same thread.
Originally posted by @FieryFlames in #70 (comment)
This is what I'm seeing:
Instead of configure_text_post_app_feed
, they use configure_text_post_app_sidecar
Originally posted by @FieryFlames in #70 (comment)
threads-web-ui
is built using the the old version of NextJS (using the /pages
router)./app
router.Is there a way to register an account threads via api?
I am using the api in React.
const onBtnClickHandler = async () => {
const threadsAPI = new ThreadsAPI();
console.log(threadsAPI);
const userID = await ThreadsAPI.getUserIDfromUsername(username);
if (!userID) {
alert("์ ์ ์ ๋ณด๊ฐ ์์ต๋๋ค.");
return;
}
const user = await threadsAPI.getUserProfile(username, userID);
console.log(JSON.stringify(user));
};
Curious if there is a plan to support pagination in retrieving threads and replies? Seems limited too 25 right now, unless im missing something. Great work BTW!
I can't seem to figure out how to Post Threads that are linked together like Thread on Twitter
Also, I tried Posting a 500 Character but instead got this error : data: { message: 'Provided text too long', status: 'fail' }
Steps to Reproduce just paste a long-form tweet in place of Content we can't place it
And Junhoyeo you really doing a great work ๐๏ธ
As each user's ID is in ascending order, can you create a script that takes information from all IDs and exports user and profile information?
I think there might be login issues with newly created accounts. After a few publishes, the API cannot connect to my HackerNews bot, neither can I. When trying to connect manually (to either Instagram or Threads), I just get generic error messages, and it looks like I can't even reset my password and use the magic login Instagram link.
When trying to connect through the API I get TypeError: Cannot read properties of undefined (reading 'split')
. It comes from line 496 of src/threads-api.ts
, because I don't get the Bearer token.
I'm not sure we can fix this through the API given that I can't even reset my bot password manually, it most likely comes from automated Instagram anti-hack protection.
So be careful when login and publishing a lot, especially with your own account (although maybe real accounts have higher hidden "limits" than newly created ones like my bot).
please public java android studio code for this library
Hello it is possible this repo can read direct message from Instagram Account. So the message can be post it on Threads, maybe with some filter like if the Account is followed by Instagram/Threads and filter message.
Im happy if it can. Thank youโ๏ธ
Looks like Threads' developers just redirected all Web browser profiles to a login route that redirects back to the homepage.
Try it here: https://www.threads.net/@zuck
PS: other functions still work, but now reverse-engineering will get tougher
Hi, I'm coming to you because I'd like to integrate the API into a NextJS project, but I'm getting an error when I try to use it and I don't know where it's coming from...
Failed to compile
./node_modules/threads-api/build/threads-api.js:1:175
Module not found: Can't resolve 'fs'
https://nextjs.org/docs/messages/module-not-found
Import trace for requested module:
./node_modules/threads-api/build/index.js
./app/api/getUser.tsx
./app/page.tsx
This error occurred during the build process and can only be dismissed by fixing the error.
Here is my code :
import { NextResponse } from 'next/server';
import { ThreadsAPI } from 'threads-api';
export const getUser = async (): Promise<NextResponse> => {
const threadsAPI = new ThreadsAPI();
const username: string = 'zuck';
const userID: string | null = await threadsAPI.getUserIDfromUsername('unyxes');
if (!userID) {
console.log(NextResponse.json({})); // Log the empty JSON response
}
const user = await threadsAPI.getUserProfile(username, userID as string);
console.log(NextResponse.json({ user }));
};
I am currently using threadsAPI.getUserIDfromUsername to get userId but it works only sometime, rest of the time it returns undefined. Is there any alternative function to be used? or any alternative approach which make sure it works all the time.
Not sure if I am doing something wrong but I keep seeing this?
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/fpods/Desktop/dev/side-projects/wa-bot/node_modules/threads-api/build/threads-api' imported from /Users/fpods/Desktop/dev/side-projects/wa-bot/node_modules/threads-api/build/index.js
at new NodeError (node:internal/errors:399:5)
at finalizeResolution (node:internal/modules/esm/resolve:326:11)
at moduleResolve (node:internal/modules/esm/resolve:945:10)
at defaultResolve (node:internal/modules/esm/resolve:1153:11)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
at link (node:internal/modules/esm/module_job:76:36) {
code: 'ERR_MODULE_NOT_FOUND'
}
@junhoyeo congratulations to you. You did a great job very quickly and dynamically.
I would like to contribute to updating the repo by adding more endpoints and make it more powerfull.
I have insufficient knowledge of reverse engineering, but I am willing to offer as much help as possible.
I also need some endpoints related to this application. I already sent you an email. I would like to support this repo and get some support from you if you contact me.
Am getting the error on Deno Deploy that thread api npm not found
Iโll replace those with Animated PNGs from Microsoft Teams...
Problem with the 'build' script: When trying to run npm run build or yarn build in the threads-api directory, the script is not recognized or found. This is despite the fact that the build script is mentioned in the project's documentation.
Cannot find module 'threads-api': When trying to build the threads-web-ui project, the build process fails with an error stating that it cannot find the 'threads-api' module. This error occurs even after attempting to install the 'threads-api' module using both npm and yarn.
Issues with 'next' version: The react-threads package seems to require a specific version of 'next' that is not being satisfied. Attempts to upgrade 'next' to the required version have not resolved this issue.
Problems with the 'start' script: Similar to the 'build' script issue, running npm start or yarn start in the threads-api directory results in an error stating that the script cannot be found.
Issues with 'yarn add ../threads-api': When trying to add the 'threads-api' module to the threads-web-ui project using yarn add ../threads-api, the build process still fails with the same error stating that it cannot find the 'threads-api' module.
These issues have prevented the successful setup and running of the project as described in the documentation. Any assistance or guidance on how to resolve these issues would be greatly appreciated.
I'm happy to be able to post automatically on Threads. I really appreciate your work.
However, there's one more function I want, that uploading in multi-threads form from the beginning.
(You can type enter three times when you upload a post in the threads app or press the 'Add to Thread' text.)
Of course, it doesn't work just by putting line-break in the parameter of the .publish() function more than three times.
I tried myself to find out if the API is different, but my reverse-engineering skills are still immature, so I haven't figured it out yet.
Is it possible to add that function? I saw that 'Reply to existing Thread' is in the roadmap you set, but personally, I would be happy if it is advanced.
Thank you.
@Digital39999: Also
noUpdateLSD
is in method options, not in class constructor.
Oops, my bad. Should've fixed this.
Originally posted by @junhoyeo in #26 (comment)
i'd suggest you convert this in python and you'll have a solid userbase of social media researchers
also, I'm happy to help/collaborate if you'd like to
`import pkg from 'threads-api';
const { ThreadsAPI } = pkg;
const main = async () => {
const threadsAPI = new ThreadsAPI({
username: 'username', // Your username
password: 'password', // Your password
});
await threadsAPI.publish('๐ค Hello World');
};
main();`
When attempting to use the publish function I receive this error:
Cannot read properties of undefined (reading 'split')
at i. (C:\Users\Colin\Documents\GitHub\threads-bot\node_modules\threads-api\build\threads-api.js:1:7479)
at C:\Users\Colin\Documents\GitHub\threads-bot\node_modules\threads-api\build\threads-api.js:1:1700
at Object.next (C:\Users\Colin\Documents\GitHub\threads-bot\node_modules\threads-api\build\threads-api.js:1:1805)
at t (C:\Users\Colin\Documents\GitHub\threads-bot\node_modules\threads-api\build\threads-api.js:1:281)
at i (C:\Users\Colin\Documents\GitHub\threads-bot\node_modules\threads-api\build\threads-api.js:1:478)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Does anyone know a solution?
Maybe publishWithImage should be combined with publish and support multiple images in the same thread.
Originally posted by @FieryFlames in #70 (comment)
Is this currently possible? I've tried looking in options couldn't find anything promising, this redirect thing they implemented is annoying.
Is there any way to delete Threads using the API?
Making a post with a PNG image it will throw the following error:
await threadsAPI.publish({
text: '๐ค test',
image: 'https://i.imgur.com/HyfKL15.png',
});
# rest of response
.....
data: {
debug_info: {
retriable: false,
type: 'ProcessingFailedError',
message: 'Request processing failed'
}
}
Using ChatGPT-4 with the webpilot plugin, like this, someone has pirated your code.
Here's the repository link: https://github.com/code-yeongyu/threads-api-openapi
This repository contains the OpenAPI YAML version of your reverse-engineered code, allowing it to be easily implemented in other languages through code generators. This renders your efforts meaningless.
I strongly do believe that such projects should not be encouraged or promoted.
It would greatly enhance the usability and security of the library if documentation regarding the formulation and retrieval of device IDs could be provided. The following suggestions are aimed at improving the user experience and preventing potential issues:
Formulating Device IDs:
It would be beneficial to have documentation on how to formulate custom device IDs, including details such as:
Retrieving Existing Device IDs:
Additionally, it would be advantageous to include documentation on retrieving existing device IDs from devices. This would provide users with the option to use a static device ID, which can help prevent the repeated generation of new IDs, potentially reducing the risk of account bans.
Advantages of Using Existing Device IDs:
To further improve user experience and decrease distinguishability, it would be ideal if the documentation could also highlight the benefits of using existing device IDs from actual devices. By leveraging an already-existing device ID, the requests made by the program would appear more similar, reducing the chances of detection or suspicion.
Providing comprehensive documentation on these topics will empower users to make informed decisions regarding device ID generation and utilization while ensuring a smoother and safer experience when using the program. Thank you for considering this feature request!
I've been trying to use the threads-api library to post to my Threads account programmatically. However, I'm encountering an ECONNRESET error and I'm unsure how to proceed.
Here's the script I'm using:
import { ThreadsAPI } from 'threads-api';
const main = async () => {
const threadsAPI = new ThreadsAPI({
username: 'my_username', // My actual username is replaced here
password: 'my_password', // My actual password is replaced here
});
await threadsAPI.publish({
text: '๐ค Hello World',
});
};
main();
When I run this script, I get the following error:
AxiosError: read ECONNRESET
...
The error suggests that the other side of the TCP conversation (in this case, the Instagram server) is unexpectedly closing the connection. I'm not sure why this is happening. My internet connection seems to be stable, and I've verified that my username and password are correct.
Could you provide any guidance on what might be causing this issue and how I could resolve it? Any help would be greatly appreciated.
What does it do?
How difficult would it be to integrate ChatGPT to:
A) read threads and like/unlike/comment based on whitelisted topics of interest extracted from the thread?
B) post new threads automatically given ChatGPT output
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.