GithubHelp home page GithubHelp logo

threads.js's People

Contributors

danya7423 avatar elijah-wright avatar jastinxyz avatar jayydoesdev avatar mastriel avatar sooluh avatar stevenlafl avatar thisisdice avatar wokesdev 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

threads.js's Issues

users.show method return ""

Hello !

I try to use the users.show method but it alway return double quote.

This is my code :

import fs from "fs";
import path from "path";

const tokenPath = path.join(process.cwd(), 'public', "token.json");

const saveToken = (token, userId) => {
    fs.writeFileSync(tokenPath, JSON.stringify({token, userId}));
};

const restoreToken = () => {
    if (!fs.existsSync(tokenPath)) return null;
    return JSON.parse(fs.readFileSync(tokenPath, "utf-8"));
};


export default function handler(req, res) {

    const {token, userId} = restoreToken();
    
    const {Client} = require('@threadsjs/threads.js');

    let client

    (async () => {

        if (token !== null && token !== undefined) {
            client = new Client({token});
            client.userId = userId;
        } else {
            client = new Client({});
            await client.login(
                "",
                ""
            );
            saveToken(client.token, client.userId);
        }

        let users = []

        await client.users.show(40372628750).then(user => {

            users = user;

            res.status(200).json({name: users})

        });

    })();
}

Thank you for your help !

add typescript

it'd be great to have types for this modules. if needed, i'm able to help

FYP Feed

Would be good to add an endpoint that gets the main feed. We currently only have a users feed as an endpoint. I dont exactly use android so I'm not able to see what those values are specifically.

GET own user

I haven't been able to find a method to get the own user's ID. Is this possible?

Login credentials / 2FA

How to utilize 2FA / checkpoint challenge code for login? Does not seem to be documented. I have an app implementing this library but is being rejected due to login rejections from Instagram. I am looking for a way one can authorize the login via instagram for my third party client.

endpoints discussion

the endpoints for threads are under i.instagram.com. endpoints I have found so far:

  • /api/v1/warning/check_offensive_multi_text/ - checks how offensive or sexual a post is. doesn't seem to do anything.
  • /api/v1/media/configure_text_only_post/ - also don't know what this does but it takes a signed body
  • /api/v1/users/USERID/info - this one is quite interesting, it's equivalent to the endpoint in getUser but it's not authenticated. you need to pass a specialized user agent starting with "Barcelona", ending with "Android", and some version in the middle.
  • /api/v1/text_feed/USERID/profile - gets a user feed.
  • /api/v1/users/search/ - explains itself pretty well, pass the q and count query strings. there's a timezone offset in there but idk what that does. needs authentication, haven't quite figured this one out yet
  • /api/v1/text_feed/recommended_users/ - recommended users, needs auth

will continue in the morning, promising stuff. hopefully someone will crack auth by then

Client instatiated with token isn't working

Steps to reproduce:

  1. Run this piece of code once
import { Client } from "@threadsjs/threads.js";
import  fs from "fs";
import path from "path";

const tokenPath = path.join(__dirname, "token.json");

const saveToken = (token: string) => {
  fs.writeFileSync(tokenPath, JSON.stringify({ token }));
};

const restoreToken = () => {
  if (!fs.existsSync(tokenPath)) return null;
  const { token } = JSON.parse(fs.readFileSync(tokenPath, "utf-8"));
  return token as string;
};

const main = async () => {
  // Try loading token from disk
  const token = restoreToken();
  console.log(token)

  // Initialize the client and login
  let client: Client;

  // If token was cached, use it
  if (token !== null) client = new Client({ token });
    
  // Else, initiate a new login process
  else {
    client = new Client({});
    await client.login(
      "<username>",
      "<password>"
    );
    saveToken(client.token);
  }

  
  const following = await client.users.following(client.userId);
  console.log(following)
};

main();
  1. Run it a second time so the client is initiated from the token cached to disk. This outputs the HTML of Instagram "Page not found" page

Suggestions for this project

I have a few suggestions for this project. I don't think it's necessary to separate the getToken method from the Client class to make it easier to access. We need the user ID and the token, so perhaps we should consider changing the class name to "Threads" or something similar, instead of "Client". The constructor function should accept an object containing the username and password, where we can obtain the token and user ID, and finally store them as class properties.

If possible, it would be good to save the token and user ID in a file. We could customize the storage path through an object when creating the class, in the constructor. Then, if the file already exists, we can simply use the existing token and user ID, eliminating the need to request a new token.

I would like to help and create a pull request, but unfortunately, I don't have the time for it.

invalid token response

I doubt if everyone is experiencing the same thing or not? i can't get valid token when using getToken function. The response from the function is always the raw response from the API (with some being truncated due to "substrings" in some variables) as shown below.

image

I think the issue is in the "end" variable

const end = text.substring(pos).search('/\\/');

But I can fix it with the code below

const pos = text.search("Bearer IGT:2:");
const sliced = text.substring(pos);
const token = sliced.substring(13, sliced.search(/\\\*?/gm));
return token;

Do I need to open a new pull request or is there another way to fix this problem?

Fetch without authentication

Can we fetch Threads data without authentication based on user ID? Data like Thread content likes replies.
This doesn't include posting and other functionalities that requires authentication

Client.postThread() no longer seems to work.

This issue was happening before the latest refactor happened.

Trying to use Client.postThread results in a response with an error code of 500 and this json body:

{ message: 'Server has an unknown issue.', status: 'fail' }

I've quintuple checked my credentials to make sure they're correct, and it still results in this error occurring.

getToken issue

token is getting invaild here how can I pass this part

const token = await getToken(username, password);

instagram logged successful but token is getting null here

Module not found error

I'm just running your example usage script after installing the module but getting the following error:

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@threadjs/threads.js'

feeds request fails

client.feeds.fetchThreads(1).then((res)=>{
console.log(res);
});

res returns website page that says Page Not Found etc.
This is similar behaviour to the following problem in another repo.

junhoyeo/threads-api#294

federation

Threads now appears to support federation:
https://www.threads.net/.well-known/webfinger?resource=acct:[email protected]
https://www.threads.net/.well-known/webfinger?resource=acct:[email protected]
https://www.threads.net/.well-known/webfinger?resource=acct:[email protected]

however, the WebFinger resource is invalid and the only instance with Threads info for this user is mastodon.social. creating this to keep track of federation work and how that'll work with threads.js

this should resolve some issues with Threads authentication not working or people getting the ID photo of death lol

getPost body typo

export async function getPost(postId) {
	const lsd = await getLsd()
	return await fetch("https://www.threads.net/api/graphql", {
    "credentials": "omit",
    "headers": {
        "Content-Type": "application/x-www-form-urlencoded",
        "X-IG-App-ID": "238260118697367",
        "X-FB-LSD": lsd,
        "Sec-Fetch-Site": "same-origin",
    },
    "body": `lsd=${lsd}&variables={"postId":"${userId}"}&doc_id=5587632691339264`,
    "method": "POST",
	}).then(async res => {
		return await res.json()
	})
}

The payload of getPost is using the wrong parameter. userId should be postId. And it should be postID not postId

Password must be sent encrypted

Old authentication now returns "An unexpected error occurred. Please try logging in again."

I have opened the app Threads again, and is now sending the login request with the password in the format: #PWD_INSTAGRAM:1:SOME NUMBER / SOME_HASHED_KEY

login error

TypeError: Cannot read properties of null (reading '0')
at parseBloksResponse (/Users/serhaterfidan/Desktop/threadsapi/node_modules/@threadsjs/threads.js/src/util/Bloks.js:30:89)
at Client.login (/Users/serhaterfidan/Desktop/threadsapi/node_modules/@threadsjs/threads.js/src/index.js:75:17)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async /Users/serhaterfidan/Desktop/threadsapi/server.js:17:5

Can't succeed to like a post

Hi! Anyone here have suceeded to like a post?
I currently use await sideClient.posts.like(postId, userToEngage.userId), it doesn't throw an error but then I cannot see likes on the Threads app

to get the replies of a user use docid: 6307072669391286

I am just quickly going through what I see. Sorry for not doing PRs :D

export async function getReply(userId) {
  const lsd = await getLsd();

  const params = {
    lsd: lsd,
    variables: JSON.stringify({ userID: userId }),
    doc_id: 6307072669391286,
  };

  const body = new URLSearchParams(params).toString();

  return await fetch("https://www.threads.net/api/graphql", {
    credentials: "omit",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
      "X-IG-App-ID": "238260118697367",
      "X-FB-LSD": lsd,
      "Sec-Fetch-Site": "same-origin",
    },
    body: body,
    method: "POST",
  }).then(async (res) => {
    return await res.json();
  });
}

Fail to login. Cannot read properties of undefined (reading 'bloks_payload')

Hi there! Today, I encountered an error when trying to log in through the IOS client.
I attached a screenshot of the error message for reference
image

I have a working code on Firebase Functions that I've been using without any issues when running it locally. However, when I tried to use it with IOS -> Firebase Functions -> threads.js client.login, something went wrong. Could you kindly assist me with this issue?
Thank you!

P.S. The same error persists even when the username and password are hardcoded.

Also, I've attached a screenshot of the working code on Firebase Functions for your reference
image

Method IDs (post and user)

Not sure if this has been answered yet but which IDs should be used for user and post?

I'm getting 'Unknown server error' when performing a reply.

Im using the post.id and user.pk_id for that post. Should the user ID be my ID? (if so, have we found a way to get that ID from the token)?

Tokens are not a constant length.

getToken() grabs a token of a length of 160 characters from the response, however it seems that not all tokens are a constant length. My token is 164 characters for instance, apparently. Using an incomplete token can cause some issues, as you'd imagine.

Make client option object optional

Hi! Just a tiny bug here.
Your documentation indicates that the options object of the Client class is not required, however if I don't pass an empty while instantiating it, I'll get the following Typescript error:

Expected 1 arguments, but got 0.ts(2554)
index.d.ts(76, 22): An argument for 'options' was not provided.

Btw thanks for this lib :)

Proxy Implementation

I noticed on #71 there are some issues regarding Instagram blocking IP addresses, and I think implementing a proxy on the HTTP agent being used might help. I'm not sure if undici supports proxies or not, but what I do know is that some other HTTP agents like axios support it.

Status and next steps

@elijah-wright, as you started the repo. What are your next steps? Discover more endpoints? Get a /fetchall API going? Would love to collaborate on a list of possible things to do.

Top of mind would be for me:

  • /fetch all endpoint + pagination
  • handle 2fa (not sure what the latest is)

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.