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

Error 400 Bad Request; when posting a photo #1756

Open
Fqlox opened this issue Feb 19, 2024 · 2 comments
Open

Error 400 Bad Request; when posting a photo #1756

Fqlox opened this issue Feb 19, 2024 · 2 comments
Labels
bug unconfirmed This issue hasn't been read/confirmed/accepted by an admin

Comments

@Fqlox
Copy link

Fqlox commented Feb 19, 2024

Bug Report

I got error 400 Bad Request; when posting a photo.

here is the simpliest code

const fs = require('fs');
const util = require("util");
const insta = require("instagram-private-api");


const readFileAsync = util.promisify(fs.readFile);

const path = './screenshot.png';


const ig = new insta.IgApiClient();

ig.state.generateDevice(username);


( async () => {


let g = await ig.account.login(username, password);
console.log(g);
console.log("logged in!")

const publishResult = await ig.publish.photo({
    file: await readFileAsync(path),
    caption: 'my caption',
  });

})();

The logging seems to work since console.log(g), print out formated dict.
screenshot.png is in 1080 × 1080.
I'm using Node.js v21.5.0.

full print of the error:


/Users/PATH/node_modules/instagram-private-api/dist/core/request.js:126
        return new errors_1.IgResponseError(response);
               ^

IgResponseError: POST /rupload_igphoto/1708349464699_0_8368615482 - 400 Bad Request;
    at Request.handleResponseError (/Users/PATH/node_modules/instagram-private-api/dist/core/request.js:126:16)
    at Request.send (/Users/PATH/node_modules/instagram-private-api/dist/core/request.js:54:28)
    at async UploadRepository.photo (/Users/PATH/node_modules/instagram-private-api/dist/repositories/upload.repository.js:18:26)
    at async PublishService.photo (/Users/PATH/node_modules/instagram-private-api/dist/services/publish.service.js:80:31)
    at async /Users/PATH/simpleUpload.js:29:23
@Fqlox Fqlox added bug unconfirmed This issue hasn't been read/confirmed/accepted by an admin labels Feb 19, 2024
@0xSuryax
Copy link

0xSuryax commented Feb 19, 2024

One potential cause of this error could be related to how the image file is being uploaded. your code uses util.promisify(fs.readFile) to read the image file asynchronously, which may not handle binary data correctly, especially if the file is large or in a format that Instagram's API doesn't accept properly.

const { get } = require('request-promise');

  const imageBuffer = await get({
      url: imgeurl,
      encoding: null, 
  });

  await ig.publish.photo({
      file: imageBuffer,
      caption: 'my caption',
  });

Try this and let me know

@Nerixyz
Copy link
Collaborator

Nerixyz commented Feb 20, 2024

screenshot.png is in 1080 × 1080

Pretty sure you need to upload JPEG.

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

3 participants