dilame / instagram-private-api

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

400 Bad Request; challenge_required #1799

Open Pleiode opened 3 weeks ago

Pleiode commented 3 weeks ago

Hey,

I have a function to post image on instagram with text.

I recently changed my instagram username and I've had ‘400 Bad Request; challenge_required’ ever since.

Yet all my connection info is good, I checked.

I also confirmed that I was the one who logged into Instagram when he asked if it was me, given a new connection.

My code

const IG_USERNAME = "****";
const IG_PASSWORD = "****";

[...]

const postToInsta = async (randomImageDoc, description) => {
    return retry(async () => {
        const ig = new IgApiClient();
        ig.state.generateDevice(IG_USERNAME);

        console.log('Attempting to login to Instagram with username:', IG_USERNAME);
        await ig.account.login(IG_USERNAME, IG_PASSWORD);
        console.log('Logged in to Instagram successfully');

        const { imageUrl, username, objects } = randomImageDoc;

        console.log('Fetching image from URL:', imageUrl);
        const imageBuffer = await axios.get(imageUrl, { responseType: 'arraybuffer' }).then(response => response.data);
        console.log('Image fetched successfully');

        const caption = `${description}\n\nCosmio's Image of the Day: shot by ${username}\n\nExplore space on Cosmio.io\n\n#astrophotography #astrophoto #astronomy #astro #cosmio #imageoftheday #space #nightsky #telescope #universe #stargaze #nightphotography #cosmos`;
        console.log('Caption:', caption);

        console.log('Attempting to publish photo to Instagram');
        await ig.publish.photo({ file: imageBuffer, caption: caption });

        console.log('Photo published successfully');

        console.log('Marking the image as posted in Firestore');
        await admin.firestore().collection('images').doc(randomImageDoc.id).update({ posted: true });
        console.log('Image marked as posted in Firestore');
    });
};

Error

In my console Firebase Functions

DEFAULT 2024-10-01T12:06:35.264569Z at Request.send (/workspace/node_modules/instagram-private-api/dist/core/request.js:54:28)

DEFAULT 2024-10-01T12:06:35.264564Z at Request.handleResponseError (/workspace/node_modules/instagram-private-api/dist/core/request.js:108:24)

DEFAULT 2024-10-01T12:06:35.264544Z Attempt 2 failed: IgCheckpointError: POST /api/v1/accounts/login/ - 400 Bad Request; challenge_required
sunmasters commented 2 days ago

There are many challenge types