dilame / instagram-private-api

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

Session Loading: Cannot delete property 'creationIndex' of [object Object] #1097

Closed Linch1 closed 4 years ago

Linch1 commented 4 years ago

Requirements

Description

I'm trying to add the session to my code, I followed some examples and tried to make it work but unsuccessfully, when it loads the datas it raises: TypeError: Cannot delete property 'creationIndex' of [object Object]. But the story is published correctly anyway (so I assume that the session is restored correctly.. ?) . But I would like to figure out what's this error means and what can cause

Code

/* tslint:disable:no-console */
/* 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 = 'ig_api_session.json';
if (!fs.existsSync(PATH)) {
  fs.writeFileSync(PATH, '', 'utf8');
}

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

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

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

(async () => {

  const ig = new IgApiClient();

  ig.state.generateDevice(USERNAME);
  await ig.qe.syncLoginExperiments();

  // This function executes after every request
  ig.request.end$.subscribe(async () => {
    const serialized = await ig.state.serialize();
    delete serialized.constants; // this deletes the version info, so you'll always use the version provided by the library
    fakeSave(serialized);
  });
  if (fakeExists()) {
    // import state accepts both a string as well as an object
    // the string should be a JSON object
    await ig.state.deserialize(fakeLoad());
  } else {
    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));
  }

  const video = await readFileAsync('datas/downloads/_wiship_/raw/c59340e417aa8a4776c8.mp4'); 
  const cover = await readFileAsync('datas/downloads/_wiship_/raw/16f4ec04&oe=5E820716.jpg'); 

  // uploading to the story
  const resStory = await ig.publish.story({
    video,
    coverImage: cover,
  });

})();

Error and Output

(node:7150) UnhandledPromiseRejectionWarning: TypeError: Cannot delete property 'creationIndex' of [object Object]
    at /home/pero/wiinsta_pro/node_modules/tough-cookie/lib/cookie.js:1283:7
    at Array.map (<anonymous>)
    at /home/pero/wiinsta_pro/node_modules/tough-cookie/lib/cookie.js:1278:34
    at MemoryCookieStore.getAllCookies (/home/pero/wiinsta_pro/node_modules/instagram-private-api/node_modules/tough-cookie/lib/memstore.js:180:3)
    at CookieJar.serialize (/home/pero/wiinsta_pro/node_modules/tough-cookie/lib/cookie.js:1273:14)
    at Bluebird.fromCallback.cb (/home/pero/wiinsta_pro/node_modules/instagram-private-api/dist/core/state.js:161:67)
    at tryCatcher (/home/pero/wiinsta_pro/node_modules/bluebird/js/release/util.js:16:23)
    at Function.Promise.fromNode.Promise.fromCallback (/home/pero/wiinsta_pro/node_modules/bluebird/js/release/promise.js:209:30)
    at State.serializeCookieJar (/home/pero/wiinsta_pro/node_modules/instagram-private-api/dist/core/state.js:161:25)
    at State.serialize (/home/pero/wiinsta_pro/node_modules/instagram-private-api/dist/core/state.js:166:48)
    at SafeSubscriber.ig.request.end$.subscribe [as _next] (/home/pero/wiinsta_pro/ig_api.js:41:39)
    at SafeSubscriber.__tryOrUnsub (/home/pero/wiinsta_pro/node_modules/rxjs/internal/Subscriber.js:205:16)
    at SafeSubscriber.next (/home/pero/wiinsta_pro/node_modules/rxjs/internal/Subscriber.js:143:22)
    at Subscriber._next (/home/pero/wiinsta_pro/node_modules/rxjs/internal/Subscriber.js:89:26)
    at Subscriber.next (/home/pero/wiinsta_pro/node_modules/rxjs/internal/Subscriber.js:66:18)
    at Subject.next (/home/pero/wiinsta_pro/node_modules/rxjs/internal/Subject.js:60:25)
    at process.nextTick (/home/pero/wiinsta_pro/node_modules/instagram-private-api/dist/core/request.js:48:42)
    at process._tickCallback (internal/process/next_tick.js:61:11)
(node:7150) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:7150) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

DEBUG

ig:state Could not find ds_user_id +0ms
  ig:request Requesting POST /api/v1/qe/sync/ +0ms
  ig:state Deserializing state of type object +463ms
  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
(node:19400) UnhandledPromiseRejectionWarning: TypeError: Cannot delete property 'creationIndex' of [object Object]
    at /home/pero/wiinsta_pro/node_modules/tough-cookie/lib/cookie.js:1283:7
    at Array.map (<anonymous>)
    at /home/pero/wiinsta_pro/node_modules/tough-cookie/lib/cookie.js:1278:34
    at MemoryCookieStore.getAllCookies (/home/pero/wiinsta_pro/node_modules/instagram-private-api/node_modules/tough-cookie/lib/memstore.js:180:3)
    at CookieJar.serialize (/home/pero/wiinsta_pro/node_modules/tough-cookie/lib/cookie.js:1273:14)
    at Bluebird.fromCallback.cb (/home/pero/wiinsta_pro/node_modules/instagram-private-api/dist/core/state.js:161:67)
    at tryCatcher (/home/pero/wiinsta_pro/node_modules/bluebird/js/release/util.js:16:23)
    at Function.Promise.fromNode.Promise.fromCallback (/home/pero/wiinsta_pro/node_modules/bluebird/js/release/promise.js:209:30)
    at State.serializeCookieJar (/home/pero/wiinsta_pro/node_modules/instagram-private-api/dist/core/state.js:161:25)
    at State.serialize (/home/pero/wiinsta_pro/node_modules/instagram-private-api/dist/core/state.js:166:48)
    at SafeSubscriber.ig.request.end$.subscribe [as _next] (/home/pero/wiinsta_pro/ig_api.js:41:39)
    at SafeSubscriber.__tryOrUnsub (/home/pero/wiinsta_pro/node_modules/rxjs/internal/Subscriber.js:205:16)
    at SafeSubscriber.next (/home/pero/wiinsta_pro/node_modules/rxjs/internal/Subscriber.js:143:22)
    at Subscriber._next (/home/pero/wiinsta_pro/node_modules/rxjs/internal/Subscriber.js:89:26)
    at Subscriber.next (/home/pero/wiinsta_pro/node_modules/rxjs/internal/Subscriber.js:66:18)
    at Subject.next (/home/pero/wiinsta_pro/node_modules/rxjs/internal/Subject.js:60:25)
    at process.nextTick (/home/pero/wiinsta_pro/node_modules/instagram-private-api/dist/core/request.js:48:42)
    at process._tickCallback (internal/process/next_tick.js:61:11)
(node:19400) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:19400) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
  ig:publish Publishing video to story: {"duration":14491,"width":640,"height":640} +0ms
  ig:upload Initializing video upload: {"retry_context":"{\"num_step_auto_retry\":0,\"num_reupload\":0,\"num_step_manual_retry\":0}","media_type":"2","xsharing_user_ids":"[]","upload_id":"676635172372","upload_media_height":"640","upload_media_width":"640","upload_media_duration_ms":"14491","for_album":"1"} +0ms
  ig:request Requesting GET /rupload_igvideo/676635172372_0_2616169475 +469ms
  ig:upload Uploading 1454312b as 676635172372 (video, mp4, not segmented). Info: {"retry_context":"{\"num_step_auto_retry\":0,\"num_reupload\":0,\"num_step_manual_retry\":0}","media_type":"2","xsharing_user_ids":"[]","upload_id":"676635172372","upload_media_height":"640","upload_media_width":"640","upload_media_duration_ms":"14491","for_album":"1"} +269ms
  ig:request Requesting POST /rupload_igvideo/676635172372_0_2616169475 +269ms
  ig:upload Uploading 88906b as 676635172372 (photo, jpeg) +5s
  ig:request Requesting POST /rupload_igphoto/676635172372_0_6089298178 +5s
  ig:request Requesting POST /api/v1/media/upload_finish/ +2s
  ig:request Requesting POST /api/v1/media/configure_to_story/ +2s
[1]+  Completato              DEBUG=ig:*
Nerixyz commented 4 years ago

Could you add the debug log?

Linch1 commented 4 years ago

Yes, added. Have i wrote something wrong or is that right and the error doesn't depends from me? @Nerixyz

burraksumer commented 4 years ago

Have you figured this out, how did you managed to do it?

rumen-makeen commented 3 years ago

Any news? Why is this issue closed? I have the same bug.

Linch1 commented 3 years ago

I don't remember why I closed the issue... Actually I didn't figure out why this error was being raised