dilame / instagram-private-api

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

Upload story Problems #1102

Closed Linch1 closed 4 years ago

Linch1 commented 4 years ago

Form

Question

I'm trying to upload ig stories using the api but i'm facins some problems. Uploading a story raise 'Cannot read property 'indexOf' of undefined' ( I'm using "electron": "^6.1.5"). I put only the relevand code here below

CODE

/* tslint:disable:no-console */
require('dotenv').config();
const  { IgApiClient, IgCheckpointError }   = require('instagram-private-api'),
        Bluebird                            = require('bluebird'),
        inquirer                            = require('inquirer'),
        fs                                  = require('fs'),
        { promisify }                       = require('util'),
        readFileAsync                       = promisify(fs.readFile);

const USERNAME = 'aaa', PASSWORD = 'bbb', PATH = 'session.txt';
if (!fs.existsSync(PATH)) {
  fs.writeFileSync(PATH, '', 'utf8');
}

function fakeSave(path, data) {
  fs.writeFileSync(path, JSON.stringify(data), 'utf8');
  return data;
}

function fakeExists(path) {
  let datas = fs.readFileSync(path, 'utf-8');
  if(datas.length > 1) return true;
  else return false;
}

function fakeLoad(path) {
  return JSON.parse(fs.readFileSync(path, 'utf-8'));
}

(async () => {
  ig = new IgApiClient();
  let shouldLogin = true;
  ig.state.generateDevice(USERNAME);
  await ig.qe.syncLoginExperiments();
    ig.request.end$.subscribe(async () => {
    const serialized = await ig.state.serialize();
    delete serialized.constants;
    fakeSave(PATH, serialized);
  });
  if (fakeExists(PATH)){
    try {
      const auth = await ig.state.deserialize(fakeLoad(PATH));
      await ig.user.info( ig.state.cookieUserId);
      console.log(auth);
      process.nextTick(async () => await ig.simulate.postLoginFlow());
      shouldLogin = false;
    } catch(e){
      console.log(e, 'SESSION NOT VALID, DOING LOGIN');
    }
    } 
    console.log('HAVE TO LOGIN?:', shouldLogin);
    if(shouldLogin == true) {
      await ig.simulate.preLoginFlow();
      console.log('here1')
    await Bluebird.try(async () => {
      const auth = await ig.account.login(USERNAME, PASSWORD);
      console.log(auth);
    }).catch(IgCheckpointError, async () => {
      console.log('err')
      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
      const { code } = await inquirer.prompt([
        {
          type: 'input',
          name: 'code',
          message: 'Enter code',
        },
      ]);
      console.log(await ig.challenge.sendSecurityCode(code));
    }).catch(e => console.log('Could not resolve checkpoint:', e, e.stack));

    await ig.simulate.postLoginFlow();
   const img = await readFileAsync('datas/downloads/video/funis_sweets&&&2cc57d14&oe=5E86625D.jpg');

  // uploading to the story
  const resStory = await ig.publish.story({
    img
  });

CONSOLE DEBUG

ig:state Could not find ds_user_id +0ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting POST /api/v1/qe/sync/ +0ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:state Deserializing state of type object +444ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:state Deserializing cookies, supportedCapabilities, language, timezoneOffset, radioType, capabilitiesHeader, connectionTypeHeader, isLayoutRTL, adsOptOut, thumbnailCacheBustingValue, clientSessionIdLifetime, pigeonSessionIdLifetime, deviceString, deviceId, uuid, phoneId, adid, build, igWWWClaim, passwordEncryptionKeyId, passwordEncryptionPubKey, authorization +0ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting undefined /api/v1/users/7540388883/info/ +436ms
run_update.js:282 undefined
run_update.js:289 HAVE TO LOGIN?: false
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting undefined /api/v1/fbsearch/suggested_searches/ +502ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting undefined /api/v1/linked_accounts/get_linkage_status/ +269ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting POST /api/v1/launcher/sync/ +301ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting undefined /api/v1/fbsearch/recent_searches/ +312ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting undefined /api/v1/qp/get_cooldowns/ +298ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting GET /api/v1/direct_v2/ranked_recipients/ +324ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting undefined /api/v1/discover/topical_explore/ +304ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting POST /api/v1/discover/mark_su_seen/ +366ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting POST /api/v1/qe/sync/ +299ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting undefined /api/v1/users/arlink_download_info/ +697ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting GET /api/v1/direct_v2/get_presence/ +269ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting POST /api/v1/attribution/log_resurrect_attribution/ +325ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Request POST [object Object] failed: {"message":"not eligible","status":"fail"} +255ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting undefined /api/v1/facebook_ota/ +6ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting undefined /api/v1/zr/token/result/ +289ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting undefined /api/v1/loom/fetch_config/ +262ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting GET /api/v1/direct_v2/ranked_recipients/ +266ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting undefined /api/v1/media/blocked/ +256ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting POST /api/v1/attribution/log_attribution/ +277ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting undefined /api/v1/fbsearch/suggested_searches/ +264ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting undefined /api/v1/direct_v2/inbox/ +342ms
run_update.js:958 /home/pero/AAA/views/index/../../datas/downloads/video/mahmoud.official.lb&&&3327fc3a&oe=5E866297.jpg true
run_update.js:984 UPLOADING STORY IMAGE
run_update.js:987 Buffer(42998) [255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 2, 0, 0, 1, 0, 1, 0, 0, 255, 237, 0, 124, 80, 104, 111, 116, 111, 115, 104, 111, 112, 32, 51, 46, 48, 0, 56, 66, 73, 77, 4, 4, 0, 0, 0, 0, 0, 95, 28, 2, 40, 0, 90, 70, 66, 77, 68, 50, 51, 48, 48, 48, 57, 56, 55, 48, 51, 48, 48, 48, 48, 49, 48, 49, 57, 48, 48, 48, 48, 49, 97, 49, 102, 48, 48, 48, 48, 48, 49, 50, 56, 48, 48, 48, 48, 102, 100, 52, …]
publish.service.ts:127 Uncaught (in promise) TypeError: Cannot read property 'indexOf' of undefined
    at Function.read16 (publish.service.ts:127)
    at Function.getVideoInfo (publish.service.ts:61)
    at PublishService.uploadAndConfigureStoryVideo (publish.service.ts:542)
    at uploadAndConfigure (publish.service.ts:300)
    at PublishService.story (publish.service.ts:397)
    at run_update.js:988
read16 @ publish.service.ts:127
getVideoInfo @ publish.service.ts:61
uploadAndConfigureStoryVideo @ publish.service.ts:542
uploadAndConfigure @ publish.service.ts:300
story @ publish.service.ts:397
(anonymous) @ run_update.js:988
async function (async)
(anonymous) @ run_update.js:928
upload_story @ run_update.js:912
interact_with @ run_update.js:1265
run @ run_update.js:1354
async function (async)
run @ run_update.js:1351
(anonymous) @ home.js:260
dispatch @ jquery.js:5238
elemData.handle @ jquery.js:5045
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting POST /api/v1/qp/batch_fetch/ +655ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting POST /api/v1/feed/timeline/ +415ms
/home/pero/AAA/node_modules/instagram-private-api/node_modules/debug/src/browser.js:183 ig:request Requesting GET /api/v1/status/get_viewable_statuses/ +2s
Nerixyz commented 4 years ago

When uploading, you need to pass a file to the method.

Linch1 commented 4 years ago

@Nerixyz I’m already doing it, i’ve followed the example. If i upload a video it works correctly but with an image it doesn’t

Nerixyz commented 4 years ago

@Linch1 You are not. You are passing img but you are supposed to pass file.

Linch1 commented 4 years ago

@Nerixyz Sry but actually i'm not understanding what you are saying... What do you mean by saying that i have to pass file not img? I saw from example that you have to pass in the function the image readed by the function readFileAsync = promisify(fs.readFile) , and the img vaiable contains that, i have not a file var to pass at the function.

I have to do it in this way ?

const img = await readFileAsync('datas/downloads/video/funis_sweets&&&2cc57d14&oe=5E86625D.jpg');

  // uploading to the story
const resStory = await ig.publish.story({
   file: img
  });
Nerixyz commented 4 years ago

@Linch1 Your latest code should work.

Linch1 commented 4 years ago

Yes it worked thanks!