Closed serhaterfidan closed 1 year ago
is it true that the token variable is null? i used three accounts with 2FA and two accounts without 2FA, and it all worked :)
instagram logged in succesful but token is getting null I am printing token on console
can you give me your email for discussions I have questions
TypeError: fetch is not a function at getToken (/Users/serhaterfidan/Desktop/threadsapi/node_modules/@threadsjs/threads.js/src/index.js:54:25) at /Users/serhaterfidan/Desktop/threadsapi/server.js:20:25 at Layer.handle [as handle_request] (/Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/layer.js:95:5) at next (/Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/route.js:144:13) at Route.dispatch (/Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/route.js:114:3) at Layer.handle [as handle_request] (/Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/layer.js:95:5) at /Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/index.js:284:15 at param (/Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/index.js:365:14) at param (/Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/index.js:376:14) at Function.process_params (/Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/index.js:421:3)
try to delete node_modules and reinstall using your package manager
I tried many times remove or install again but still same error
I am using "@threadsjs/threads.js": "^1.5.4"
what is your node version? undici requires 14 and above, so if you're on a lower version, update node
v14.21.3
I update node.js version to v18.16.1 and error changed like this
TypeError: getToken is not a function at /Users/serhaterfidan/Desktop/threadsapi/server.js:15:25 at Layer.handle [as handle_request] (/Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/layer.js:95:5) at next (/Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/route.js:144:13) at Route.dispatch (/Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/route.js:114:3) at Layer.handle [as handle_request] (/Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/layer.js:95:5) at /Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/index.js:284:15 at param (/Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/index.js:365:14) at param (/Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/index.js:376:14) at Function.process_params (/Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/index.js:421:3) at next (/Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/index.js:280:10)
yeah, getToken got removed in 1.6.1 which got pushed this morning. try using something like this:
(async () => {
const client = new Client();
await client.login('username', 'password');
})();
I update the library and all code updated error is
TypeError: Cannot destructure property 'token' of 'undefined' as it is undefined. at new Client (/Users/serhaterfidan/Desktop/threadsapi/node_modules/@threadsjs/threads.js/src/index.js:12:16) at /Users/serhaterfidan/Desktop/threadsapi/server.js:15:20 at Layer.handle [as handle_request] (/Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/layer.js:95:5) at next (/Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/route.js:144:13) at Route.dispatch (/Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/route.js:114:3) at Layer.handle [as handle_request] (/Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/layer.js:95:5) at /Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/index.js:284:15 at param (/Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/index.js:365:14) at param (/Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/index.js:376:14) at Function.process_params (/Users/serhaterfidan/Desktop/threadsapi/node_modules/express/lib/router/index.js:421:3)
I'll take a look at it
ah, ok, you need to use new Client({});
, not new Client();
. i'll fix that in the readme, thanks
I updated and then error
TypeError: Cannot read properties of undefined (reading 'logged_in_user') at Client.login (/Users/serhaterfidan/Desktop/threadsapi/node_modules/@threadsjs/threads.js/src/index.js:77:28) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
@sooluh you know more about this bloks stuff more than me lol. if parseBloksResponse is wrong, could mean that the username/password is wrong.
username and password is true I checked on instagram
try updating to 1.6.2 and see what happens
I updated and same error do you have any test accounts for try
I'll try again, soon.
if you can, edit the file at /Users/serhaterfidan/Desktop/threadsapi/node_modules/@threadsjs/threads.js/src/index.js
and put "console.log(bloks.login_response)" above it. is there anything?
I instead encountered an error like this with the latest version:
constructor({ token, userAgent, appId }) {
^
TypeError: Cannot destructure property 'token' of 'undefined' as it is undefined.
you have to pass an empty object into the client constructor.
Sure, I found it and I will fix it now, along with the error I just encountered.
if you can, edit the file at
/Users/serhaterfidan/Desktop/threadsapi/node_modules/@threadsjs/threads.js/src/index.js
and put "console.log(bloks.login_response)" above it. is there anything?console logged undefined
try logging bloks
, it's probably giving you an error
console logged [object Object]
It's just a placement error. Those who use 2FA cannot directly retrieve logged_in_user.pk. This only works for accounts without 2FA.
what should I do about this
should be fixed in 1.6.3
TypeError: client.getToken is not a function at /Users/serhaterfidan/Desktop/threadsapi/server.js:18:26 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
this my code
try { const { username, password } = req.query; const userId = req.params.userId;
const client = new Client({});
await client.login(username, password);
const token = client.getToken(); // Retrieve the token from the Client instance
if (!token) {
return res.status(401).json({ error: 'Invalid credentials' });
}
const user = await client.users.fetch(userId);
res.json(user);
} catch (error) { console.error(error); res.status(500).json({ error: 'An error occurred during computation' }); }
you need to use client.token if you want to get the token from the client
Token is :undefined
const client = new Client({}); await client.login(username, password);
const token = client.token; // Retrieve the token from the Client instance
console.log(`Token is :${token}`);
if (!token) {
return res.status(401).json({ error: 'Invalid credentials' });
}
@elijah-wright, I have just submitted a pull request. I have fixed it so that even when the Client class is initialized without an empty object, it can still retrieve the userId correctly for both accounts with and without 2FA enabled.
@elijah-wright Your types/index.d.ts is wrong, you need this:
public login(username: string, password: string): Promise<void>;
Afterwards in typescript I can use:
let client = new Client({});
await client.login(username, password);
Can you update that? (btw your 1.6.3 does otherwise work and I get a token)
still same Token is :undefined
let client = new Client({}); await client.login(username, password);
const token = client.token; // Retrieve the token from the Client instance
console.log(`Token is :${token}`);
if (!token) {
return res.status(401).json({ error: 'Invalid credentials' });
}
@serhaterfidan Please try to update to the latest version available.
I am using 1.6.4
could you console.log(client)
? you might need to wrap everything in an async function
Client { _events: [Object: null prototype] {}, _eventsCount: 0, _maxListeners: undefined, token: null, userAgent: 'Barcelona 289.0.0.77.109 Android', appId: '238260118697367', androidId: '3hp0if058dk00000', userId: null, rest: RESTManager {}, users: UserManager {}, posts: PostManager {}, feeds: FeedManager {},
} TypeError: Cannot read properties of undefined (reading 'logged_in_user') at Client.login (/Users/serhaterfidan/Desktop/threadsapi/node_modules/@threadsjs/threads.js/src/index.js:135:28) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async /Users/serhaterfidan/Desktop/threadsapi/server.js:17:5
What you are currently testing, is it using 2FA or not?
try 1.6.5
I don't have 2FA on my account
try 1.6.5
I think that code will remove the userId, does it mean not everyone has a userId? This is very strange.
I updated but error is same
Client { _events: [Object: null prototype] {}, _eventsCount: 0, _maxListeners: undefined, token: null, userAgent: 'Barcelona 289.0.0.77.109 Android', appId: '238260118697367', androidId: 'q3icvec75r40000', userId: null, rest: RESTManager {}, users: UserManager {}, posts: PostManager {}, feeds: FeedManager {},
} TypeError: Cannot read properties of undefined (reading 'logged_in_user') at Client.login (/Users/serhaterfidan/Desktop/threadsapi/node_modules/@threadsjs/threads.js/src/index.js:135:28) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async /Users/serhaterfidan/Desktop/threadsapi/server.js:17:5
do you have any test account for test
What happens if you add console.log(JSON.stringify(bloks));
on line 134 of /Users/serhaterfidan/Desktop/threadsapi/node_modules/@threadsjs/threads.js/src/index.js
?
{"error":{"uid":{},"code":1,"message":"Unmapped IG Error: This IG Error was not mapped to an Error Code. To fix it, update the error tool under 'CAA' to map it to an Error Code.","error_user_title":"","error_subcode":3540001,"error_user_msg":"challenge_required","error_data":{"url":"https://i.instagram.com/challenge/AXFFZ_wIFA7sub4MHuaGzs3HUJDU22k_BgCDnz406sREk3A943NZIBhNb2XUB8Fvc224aTc/AfzSC2aoP5qwsZrIiT6RmizVKvHX-sKyL7ZVdgmbLUrkTWY35NGR7f5Qxu67ejUuFQwPKgys7U-sLA/","api_path":"/challenge/AXFFZ_wIFA7sub4MHuaGzs3HUJDU22k_BgCDnz406sREk3A943NZIBhNb2XUB8Fvc224aTc/AfzSC2aoP5qwsZrIiT6RmizVKvHX-sKyL7ZVdgmbLUrkTWY35NGR7f5Qxu67ejUuFQwPKgys7U-sLA/","hide_webview_header":true,"lock":true,"logout":false,"native_flow":true,"flow_render_type":0,"challenge_context":{"step_name":"","nonce_code":"AfzkvmeG5NK15lobGnJYLjKWoBAO6sbp4mTsIBDm9OtXzvoVkmd4di6gpxMVUYa2mad25XSA978GCw","user_id":"AXHNfftbsNK4yA8Jx7xXplcunOCHbpkSY2P2pcjbn0rJYe3KJv4A4gJ8V0DGkUTMZ8lloNA","first_factor_code":"YUGA9l13dydJ0vE7NLqYutx9fvQzMQnyBCtcegDHWK7ysGabyHXjvcdSG3J62E6o","is_stateless":false,"present_as_modal":false}}}}
Damn, your account has been hit with a checkpoint. Please check your Instagram application, you may be required to change your password.
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