dilame / instagram-private-api

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

Login 400 Bad Request #1469

Open 1312rahulshah opened 3 years ago

1312rahulshah commented 3 years ago

Bug Report

Form

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

Requirements

Description

This code used to work smoothly before but since the past few days i'm facing this Login issue. My accounts are not blocked. When i login on official website/app the accounts are working, but through this code i'm getting 400 Bad Request

Code

  async login() {

    helpers.telegram_send_message("Login started for username: " + this.config['IG_USERNAME']);

    this.ig_client = new IgApiClient.IgApiClient();

    this.ig_client.state.generateDevice(this.config['IG_USERNAME']);

    await this.ig_client.simulate.preLoginFlow().then(resp => {
      helpers.telegram_send_message('PreLogin success for username: ' + this.config['IG_USERNAME']);
    }).catch(error => {
      helpers.telegram_send_message('PreLogin failed for username: ' + this.config['IG_USERNAME'], "exception");
      helpers.telegram_send_message(error, "exception");
    });;

    console.log("Logging in", this.config['IG_USERNAME'], this.config['IG_PASSWORD'])
    await this.ig_client.account.login(this.config['IG_USERNAME'], this.config['IG_PASSWORD'])
      .then(resp => {
        helpers.telegram_send_message('Login success for username: ' + this.config['IG_USERNAME']);
        // console.log(resp);
      }).catch(error => {
        helpers.telegram_send_message('Login Failed for username: ' + + this.config['IG_USERNAME'], "exception");
        helpers.telegram_send_message(error, "exception");
      });

    await this.ig_client.simulate.postLoginFlow();
  }

Error and Output

(node:15048) UnhandledPromiseRejectionWarning: IgResponseError: POST /api/v1/accounts/login/ - 400 Bad Request;
    at Request.handleResponseError (D:\react_projects\instagram-testxxx\node_modules\instagram-private-api\dist\core\request.js:125:16)
    at Request.send (D:\react_projects\instagram-testxxx\node_modules\instagram-private-api\dist\core\request.js:53:28)
(node:15048) 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(). (rejection id: 1)
(node:15048) [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.
1312rahulshah commented 3 years ago

Does not work even after removing preloginflow

1312rahulshah commented 3 years ago

<b>Exception:</b> IgResponseError: POST /api/v1/accounts/login/ - 400 Bad Request; (node:15304) UnhandledPromiseRejectionWarning: IgLoginRequiredError: GET /api/v1/direct_v2/ranked_recipients/?mode=reshare&query=&show_threads=true - 403 Forbidden; login_required at Request.handleResponseError (D:\react_projects\instagram-testxxx\node_modules\instagram-private-api\dist\core\request.js:113:24) at Request.send (D:\react_projects\instagram-testxxx\node_modules\instagram-private-api\dist\core\request.js:53:28) (node:15304) 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(). (rejection id: 1) (node:15304) [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.

kingbotss commented 2 years ago

For some accounts login not work, try to send request as http2. #1538