threadsjs / threads.js Goto Github PK
View Code? Open in Web Editor NEWA Node.js library for the Threads API
License: MIT License
A Node.js library for the Threads API
License: MIT License
It should have proper info on how to use it
this library probably should be object-oriented with classes
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 !
Right now here is the WIP:
https://github.com/stevenlafl/threads-web-client/blob/master/src/pages/api/feed.ts
and associated Feed component: https://github.com/stevenlafl/threads-web-client/blob/master/src/app/Feed.tsx
I need to get it to display more. It looks like I'm limited to 8, and refreshing may or may not get me a similar result set. Is there pagination available?
it'd be great to have types for this modules. if needed, i'm able to help
await client.users.fetch(25025320).then(user => {
console.log(user);
});
resulting in
{"message": "useragent mismatch", "status": "fail"}
I set the client user agent to the following https://www.whatismybrowser.com/detect/what-is-my-user-agent/
attempted my desktop as well as the simulator user agent.
Hi there, Looks cool just wondered how you were finding these endpoints. I tried to proxy my phone but it seems they employ SSL pinning so had no luck. Let me know
Can we use this without Node JS? Like in just React JS
I think the title is self-explanatory, hehe
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.
I haven't been able to find a method to get the own user's ID. Is this possible?
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.
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 authwill continue in the morning, promising stuff. hopefully someone will crack auth by then
Can this feature develop for user followings?
Steps to reproduce:
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();
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.
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.
I think the issue is in the "end" variable
Line 55 in 292df7d
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?
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
keeping track of typings in this issue
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.
how can I make login without username and password and just use with Instagram Auth and token for Threads Client
When you perform a few requests, you get logged out of the system with
{
"message": "login_required",
"error_title": "You've Been Logged Out",
"error_body": "Please log back in.",
"logout_reason": 8,
"status": "fail"
}
when I call
const token = await getToken(username, password);
token is getting invalid here but logged in instagram succesfull but as suspicious login and instagram force change password how can we this safe call and also handle token 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
thank you, but i receive `undefined` after logging the token
Originally posted by @esau-morais in #62 (comment)
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'
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.
Hello again!
I've tried to use await client.users.search("zuck", 2)
to get 2 results about "zuck" but got tens of objects as response.
Any idea why?
{
"message": "challenge_required",
"challenge": {
"url": "https://www.instagram.com/accounts/suspended/",
"api_path": "/challenge/",
"hide_webview_header": true,
"lock": true,
"logout": false,
"native_flow": true,
"flow_render_type": 0
},
"status": "fail"
}
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
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
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
getting undefined
in base
endpoint
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
Hello
Would it be possible to get support in adding attachments to be included in the client.posts.create options?
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
Hi Problem
Error : Error: Token is required.
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();
});
}
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
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
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)?
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.
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 :)
@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:
When you send back the next max id in those two functions, you just get back the same list without pagination.
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.