Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

400 Bad Request; challenge_required #1799

Open
Pleiode opened this issue Oct 1, 2024 · 0 comments
Open

400 Bad Request; challenge_required #1799

Pleiode opened this issue Oct 1, 2024 · 0 comments
Labels
bug unconfirmed This issue hasn't been read/confirmed/accepted by an admin

Comments

@Pleiode
Copy link

Pleiode commented Oct 1, 2024

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
@Pleiode Pleiode added bug unconfirmed This issue hasn't been read/confirmed/accepted by an admin labels Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unconfirmed This issue hasn't been read/confirmed/accepted by an admin
Projects
None yet
Development

No branches or pull requests

1 participant