dilame / instagram-private-api

NodeJS Instagram private API SDK. Written in TypeScript.
MIT License
5.93k stars 1.14k forks source link

IgResponseError when trying to fetch dm thread items #1387

Open dcts opened 3 years ago

dcts commented 3 years ago

Form

Put an [x] if you meet the condition, else leave [ ].

Requirements

Platform

Description

Fetching DM threads stopped working and throws IgResponseError. This is the line of code in the instagram-private-api that throws the error. Maybe the request to instagram is not working properly anymore?

// login
const username = "yourusername";
const password = "yourpassword";
const ig = new IgApiClient();
ig.state.generateDevice(username); // generate device
await ig.simulate.preLoginFlow(); 
const user = await ig.account.login(username, password);
process.nextTick(async () => await ig.simulate.postLoginFlow());

// fetch all direct threads (message threads)
let directInbox = await ig.feed.directInbox(user.pk);
let threads = []; // bucket for all threads
do {
  console.log("loading batch of DM-threads");
  const threadsBatch = await directInbox.items(); // <-- THIS THROWS THE ERROR
  threads = threads.concat(threadsBatch);
  } while (directInbox.isMoreAvailable());
console.log(`🎉 successfully fetched ${threads.length} DM threads`);

Error and Output

(node:4) UnhandledPromiseRejectionWarning: IgResponseError: GET /api/v1/direct_v2/inbox/?visual_message_return_type=unseen&thread_message_limit=10&persistentBadging=true&limit=20 - 560 -;
  at Request.handleResponseError (/app/node_modules/instagram-private-api/dist/core/request.js:125:16)
  at Request.send (/app/node_modules/instagram-private-api/dist/core/request.js:53:28)
  at async DirectInboxFeed.request (/app/node_modules/instagram-private-api/dist/feeds/direct-inbox.feed.js:21:26)
  at async Client.login (/app/node_modules/@androz2091/insta.js/src/structures/Client.js:385:23)
  (node:4) 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:4) [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.
singla96 commented 3 years ago

+1

Nerixyz commented 3 years ago

Does this happen if the version of the api is a newer one? It's currently very old.

singla96 commented 3 years ago

tested on 1.43.3. Using this from few months and it used to work well, but recently it started giving error

Nerixyz commented 3 years ago

tested on 1.43.3. Using this from few months and it used to work well, but recently it started giving error

Sorry, I was referring to the instagram constants used.

singla96 commented 3 years ago

@Nerixyz okay. Its not limited to messages anymore. IgResponseError: POST /api/v1/accounts/login/ - 400 Bad Request; There was an error with your request. Please try again. The same request that was working before.

DebuggingUnicorn commented 1 year ago

Has anyone solved this problem? For me, it only occurs with one particular Instagram account, and I don't have any issues with other accounts. Could it be related to specific Instagram account settings, or is there something else I should be aware of? Any help or suggestions would be greatly appreciated.

danielegarciav commented 1 year ago

@DebuggingUnicorn I have a suspicion that for some selected users, Instagram is disabling this endpoint and instead forces the client to use MQTT. My web client recently started using MQTT over websockets to fetch DM thread items, with no references in devtools at all to the older HTTP API.