dilame / instagram-private-api

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

POST /api/v1/media/configure/?video=1 - 403 Forbidden #1640

Open rafaelgdn opened 2 years ago

rafaelgdn commented 2 years ago

Hi.

Im trying to publish a video and i got this VideoSourceDurationCheckException error.

Anyone can help me with this?

my code:

import { S3 } from 'aws-sdk';
import { IgApiClient } from 'instagram-private-api';
import fs from 'fs';

const s3 = new S3();
const ig = new IgApiClient();
const bucket = 'posts';
const { INSTA_USER, INSTA_PASS } = process.env;

ig.state.generateDevice(INSTA_USER);

export const main = async () => {
  try {
    await ig.account.login(INSTA_USER, INSTA_PASS);

    const { Contents } = await s3.listObjectsV2({ Bucket: bucket, MaxKeys: 2, Prefix: 'memes/geral' }).promise();

    const files = await Promise.all(Contents.map(async ({ Key }) => {
      const file = await s3.getObject({
        Bucket: bucket,
        Key,
      }).promise();

      return file.Body;
    }));

    const publishResult = await ig.publish.video({
      video: files[0],
      coverImage: await fs.readFileAsync("../../src/assets/cover.png")
    });

    console.dir({ publishResult }, { depth: null })
  } catch (error) {
    console.error(error);
    throw error;
  }
}

When I get a file from s3, it comes in the following format. I'm taking the content of the body property and put it in the video property of the publish method. Is it right? I also tried to save the file with fs.writeFile and dps use readFileSync like in the example but it also gave the same error.

{
    AcceptRanges: 'bytes',
    LastModified: 2022-08-04T23:15:24.000Z,
    ContentLength: 3252472,
    ETag: '"c491cfe2fb5bc29777fc34391fc1d56a"',
    ContentType: 'application/octet-stream',
    Body: Buffer(3252472) [Uint8Array] [
        0,   0,   0,  32, 102, 116, 121, 112, 105, 115, 111, 109,
        0,   0,   2,   0, 105, 115, 111, 109, 105, 115, 111,  50,
       97, 118,  99,  49, 109, 112,  52,  49,   0,   0, 209,   0,
      109, 111, 111, 118,   0,   0,   0, 108, 109, 118, 104, 100,
        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        0,   0,   3, 232,   0,   0, 250,  17,   0,   1,   0,   0,
        1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        0,   0,   0,   0,
      ... 3252372 more items
    ]
  }

error:

{
    "errorMessage": "POST /api/v1/media/upload_finish/?video=1 - 400 Bad Request; server processing error: VideoSourceDurationCheckException",
    "errorType": "IgUploadVideoError",
    "stackTrace": [
        "IgUploadVideoError: POST /api/v1/media/upload_finish/?video=1 - 400 Bad Request; server processing error: VideoSourceDurationCheckException",
        "    at C:\\Users\\User\\Desktop\\dev\\Insta\\.webpack\\service\\src\\functions\\webpack:\\instagram-private-api\\dist\\services\\publish.service.js:26:1",  
        "    at tryCatcher (C:\\Users\\User\\Desktop\\dev\\Insta\\.webpack\\service\\src\\functions\\webpack:\\bluebird\\js\\release\\util.js:16:1)"
}

video: video.mp4

rafaelgdn commented 2 years ago

For those who have the same problem, this error happens because the video is longer than 60 seconds. Although instagram accepts videos of up to 3 minutes, it seems that the API only accepts videos of up to 60 seconds.

And there are still other specifications that we need to follow to be able to post a video, follow: video specifications

Does anyone know a way to convert any video to the format that instagram accepts?

now every video i try to upload i got this error:

{
    "errorMessage": "POST /api/v1/media/configure/?video=1 - 403 Forbidden; ",
    "errorType": "IgConfigureVideoError",
    "stackTrace": [
        "IgConfigureVideoError: POST /api/v1/media/configure/?video=1 - 403 Forbidden; ",
        "    at PublishService.video (C:\\Users\\User\\Desktop\\dev\\Insta\\.webpack\\service\\src\\functions\\webpack:\\instagram-private-api\\dist\\services\\publish.service.js:123:1)",        
        "    at C:\\Users\\User\\Desktop\\dev\\Insta\\.webpack\\service\\src\\functions\\webpack:\\src\\functions\\cronFreefireMemes.js:71:31",
        "    at async Promise.all (index 1)",
        "    at main (C:\\Users\\User\\Desktop\\dev\\Insta\\.webpack\\service\\src\\functions\\webpack:\\src\\functions\\cronFreefireMemes.js:47:5)"
    ]
}
TheNewAggregator commented 2 years ago

Hello @rafaelgdn ,

I'm having a lot of checkpoint problems lately using this API. Maybe we can collaborate!

My gmail is danielpaixaodp2021@gmail.com

Did you have this kind of problem and fix it? Can you email me so we can try to talk about our objectives?