Giter Site home page Giter Site logo

junhoyeo / threads-api Goto Github PK

View Code? Open in Web Editor NEW
1.6K 21.0 134.0 17.36 MB

Unofficial, Reverse-Engineered Node.js/TypeScript client for Meta's Threads. Web UI Included.

Home Page: https://threads.junho.io

License: MIT License

TypeScript 96.30% JavaScript 2.28% CSS 1.42%
instagram instagram-api meta threads threads-bridge threads-api threads-client web-ui barcelona

threads-api's People

Contributors

0xero7 avatar aayushgithub avatar aerglonus avatar aleclarson avatar alllz avatar aminedjohar avatar billy-the-ape avatar cedriking avatar corard avatar digital39999 avatar enggaraziz avatar farizrifqi avatar firtoz avatar imgbot[bot] avatar irajatdas avatar jamelhammoud avatar junhoyeo avatar mineru98 avatar nainish-rai avatar newt0n avatar sethusenthil avatar sooluh avatar stevenlafl avatar steveyout avatar sudarshanmg avatar suvam0451 avatar swarajbachu avatar yssf-io avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

threads-api's Issues

Can't publish anything: UnhandledPromiseRejectionWarning: TypeError: i.sent(...).data.split(...)[1].split(...)[0].replaceAll is not a function

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.

Reverse engineering process

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! :)

getToken is failing

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

image

Remake threads-web-ui using the Next JS app router.

  • The current threads-web-ui is built using the the old version of NextJS (using the /pages router).
  • It is advisable to migrate it to the newest version that makes use of the stable /app router.
    PS: I can work on it and send a PR.

TypeError: threads_api__WEBPACK_IMPORTED_MODULE_3__.ThreadsAPI.getUserIDfromUsername is not a function

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));
};

Why does this error occur?
แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-07-08 แ„‹แ…ฉแ„Œแ…ฅแ†ซ 11 12 37

How to Post Long Threads Like One after another linked together

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 ๐Ÿ‘๏ธ

Can't login anymore - Cannot read properties of undefined (reading 'split')

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).

Get user's timeline?

Sorry if I misunderstand the API but is there a way to see the "timeline" of a logged-in user, meaning the page that comes up when you open the app and press press the home icon?

image

I am referring to this:

image

Integrated with Direct Message Instagram

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โœŒ๏ธ

Module not found: Can't resolve `fs` (Can't use the API on a NextJS Project)

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 }));
};

Issue in Fetching UserId from Username

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.

Module not found?

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'
}

Add More Endpoint

@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.

[email protected]

Cannot run API on server

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.

image

[New Feature Request] Upload multi threads or upload post as reply

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.

make it in python

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

Cannot read properties of undefined (reading 'split')

`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?

Fetch posts with credentials

Is this currently possible? I've tried looking in options couldn't find anything promising, this redirect thing they implemented is annoying.

Bad Request processing failed if image is png

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'
      }
    }

Someone pirated your code.

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.

๐Ÿ“ Documentation Request - Formulating and Retrieving Device IDs

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:

  1. Formulating Device IDs:
    It would be beneficial to have documentation on how to formulate custom device IDs, including details such as:

    • Length: Specify the recommended or required length(s) for device ID strings.
    • Valid Prefixes: Identify the acceptable prefixes for different types of devices. For example, 'android-' for Android devices.
  2. 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.

  3. 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!

ECONNRESET Error When Trying to Post to Threads

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.

Can't run the web client

Hi, first of all, amazing job at creating an API at such a fast rate, it's not even day one of the platform.

However, I want to use the web client, but nothing shows up:
image
And when i try accessing any username:
image

I'm running the script with npm run dev, am i doing something wrong?
image

ChatGPT integration

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.