dilame / instagram-private-api

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

400 Bad Request; No ID given #1173

Closed ondersumer07 closed 4 years ago

ondersumer07 commented 4 years ago

Bug Report

Form

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

Requirements

Description

The problem is probably about API version of Instagram. I'm trying to compile TS to JS and make it work in the terminal.

Code

const { IgApiClient } = require('instagram-private-api');
const { readFile } = require('fs');
const { promisify } = require('util');

const readFileAsync = promisify(readFile);

const ig = new IgApiClient();

ig.qe.syncLoginExperiments();

async function login() {
    ig.state.generateDevice(process.env.IG_USERNAME);
    await ig.account.login(process.env.IG_USERNAME, process.env.IG_PASSWORD);
};

(async () => {
await login().catch(console.log);

const videoPath = '1.mp4';
const coverImage = '1.png';

const publishResult = await ig.publish.video({
    video: await readFileAsync(videoPath),
    coverImage: await readFileAsync(coverImage),
    caption: 'asd'
});

console.log(publishResult);

})().catch(console.log);

Error and Output

(node:11068) UnhandledPromiseRejectionWarning: IgResponseError: POST /api/v1/qe/sync/ - 400 Bad Request; No ID given
    at Request.handleResponseError (C:\Users\Önder Sümer\Desktop\ins\node_modules\instagram-private-api\dist\core\request.js:125:16)
    at Request.send (C:\Users\Önder Sümer\Desktop\ins\node_modules\instagram-private-api\dist\core\request.js:53:28)
(node:11068) 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:11068) [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.
TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be one of type string, Buffer, TypedArray, or DataView. Received type undefined
    at invalidArrayBufferView (internal/crypto/cipher.js:100:10)
    at Cipheriv.update (internal/crypto/cipher.js:157:11)
    at AccountRepository.encryptPassword (C:\Users\Önder Sümer\Desktop\ins\node_modules\instagram-private-api\dist\repositories\account.repository.js:70:52)
    at AccountRepository.login (C:\Users\Önder Sümer\Desktop\ins\node_modules\instagram-private-api\dist\repositories\account.repository.js:15:42)
{ IgUploadVideoError: GET /rupload_igvideo/1588729111990_0_4920723972 - 403 Forbidden; login_required
    at Bluebird.try.catch.error (C:\Users\Önder Sümer\Desktop\ins\node_modules\instagram-private-api\dist\services\publish.service.js:94:19)
    at tryCatcher (C:\Users\Önder Sümer\Desktop\ins\node_modules\bluebird\js\release\util.js:16:23)
    at C:\Users\Önder Sümer\Desktop\ins\node_modules\bluebird\js\release\catch_filter.js:17:41
    at tryCatcher (C:\Users\Önder Sümer\Desktop\ins\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (C:\Users\Önder Sümer\Desktop\ins\node_modules\bluebird\js\release\promise.js:547:31)
    at Promise._settlePromise (C:\Users\Önder Sümer\Desktop\ins\node_modules\bluebird\js\release\promise.js:604:18)
    at Promise._settlePromise0 (C:\Users\Önder Sümer\Desktop\ins\node_modules\bluebird\js\release\promise.js:649:10)
    at Promise._settlePromises (C:\Users\Önder Sümer\Desktop\ins\node_modules\bluebird\js\release\promise.js:725:18)
    at _drainQueueStep (C:\Users\Önder Sümer\Desktop\ins\node_modules\bluebird\js\release\async.js:93:12)
    at _drainQueue (C:\Users\Önder Sümer\Desktop\ins\node_modules\bluebird\js\release\async.js:86:9)
    at Async._drainQueues (C:\Users\Önder Sümer\Desktop\ins\node_modules\bluebird\js\release\async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (C:\Users\Önder Sümer\Desktop\ins\node_modules\bluebird\js\release\async.js:15:14)
    at processImmediate (internal/timers.js:443:21) videoInfo: { duration: 59907, width: 640, height: 360 } }
Nerixyz commented 4 years ago

You're calling syncLoginExperiments() before you're generating a device.

ondersumer07 commented 4 years ago

Yep, it was pretty late at night and I was very tired I missed that one. Here's the working code for future references:

    const { IgApiClient } = require('instagram-private-api');
    const { readFile } = require('fs');
    const { promisify } = require('util');

    const ig = new IgApiClient();

    ig.state.generateDevice("username");

    (async () => {
        await ig.simulate.preLoginFlow();
        await ig.account.login("username", "password");
        console.log("logged in!")
        process.nextTick(async () => await ig.simulate.postLoginFlow());

        const videoPath = 'video.mp4';
        const coverImage = 'thumb.jpg';

        const publishResult = await ig.publish.video({
            video: await readFileAsync(videoPath),
            coverImage: await readFileAsync(coverImage),
            caption: 'description'
        });

        console.log(publishResult);

    })().catch(console.log);
trentona commented 4 years ago

Same thing here, Im getting it on a few new accounts. Accounts previously logged in work fine when re-logging in. I am calling loginexp second.

IgResponseError: POST /api/v1/qe/sync/ - 400 Bad Request; No ID given at Request.handleResponseError (/srv/node_modules/instagram-private-api/dist/core/request.js:125:16) at Request.send (/srv/node_modules/instagram-private-api/dist/core/request.js:53:28) at

Nerixyz commented 4 years ago

@trentona make sure you're loading and saving your state properly.

trentona commented 4 years ago

It works with fine previous accounts though? Maybe I should only be doing "const ig = new IgApiClient;" once?

Bluebird.try (async () => {
    const ig = new IgApiClient;
     ig.state.generateDevice(myUsername);
     await ig.qe.syncLoginExperiments();

     ig.state.generateDevice(String(myUsername));
     ig.state.proxyUrl = process.env.IG_PROXY;
     const auth = await ig.account.login(String(myUsername), String(myPassword));
     console.log(JSON.stringify(auth));
}).catch(IgCheckpointError, async () => {
    const ig = new IgApiClient;
    Bluebird.try(async () => {
        const auth = await ig.account.login(String(myUsername), String(myPassword));
        console.log(auth);
        console.log(ig.state.checkpoint); 
        await ig.challenge.auto(true); 
        console.log(ig.state.checkpoint); 

...

ondersumer07 commented 4 years ago

Why are you generating your device twice?

Try to generate it once, this might be the issue.

Nerixyz commented 4 years ago

Maybe I should only be doing "const ig = new IgApiClient;" once?

Your IgApiClient has all your state information. So if you create a new instance, it won't have the state.

ig.state.generateDevice(String(myUsername));

This is unnecessary.

trentona commented 4 years ago

Thanks, not sure how I did that. I get a different error now though.

I just updated and tested a new account and account I have previously used again. The new account did not work and gave me this error. Am I missing part of the challenges required? Iv gotten the otc to work before but it seems to just finish the function before the checkpointError completes. The otc was not being sent email/phone number attached to the instagram account. Instagram does notify a login attempt though, but does not supply the otc either.

Could I have flagged out the login through insta? Iv noticed about 12 posts in a hour can get your account flagged and it will auto delete your images. But I have never had issues with login like this but I feel it may be a possibility.

IgCheckpointError: POST /api/v1/accounts/login/ - 400 Bad Request; challenge_required at Request.handleResponseError (/srv/node_modules/instagram-private-api/dist/core/request.js:107:24) at Request.send (/srv/node_modules/instagram-private-api/dist/core/request.js:53:28) at

   .catch(IgCheckpointError, async () => {

    Bluebird.try(async () => {

     const auth = await ig.account.login(String(myUsername), String(myPassword));
     console.log(auth);

     console.log(ig.state.checkpoint); // Checkpoint info here
     await ig.challenge.auto(true); // Requesting sms-code or click "It was me" button
     console.log(ig.state.checkpoint); // Challenge info here

      await functions.database.ref('/users/' + myUsername + '/otc')
         .onCreate((snapshot, context) => {
           // Grab the current value of what was written to the Realtime Database.
           const code =  snapshot.val();
            console.log('something happened');
             myCode = snapshot.val();

           console.log(ig.challenge.sendSecurityCode(myCode));
lucy66687 commented 3 months ago

I also met this problem, may I ask your final solution?