question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

My session function doesn't seem to work, what's the wrong?

See original GitHub issue

General Question

Read the Notes and fill out the form. Switch to Preview for reading.

Notes

Your issue will be closed if you violate any rule below.

  • You need to include a meaningful descriptions and e.g. a screenshot.
  • You do not include screenshots of your code.
  • Read the Docs.
  • Capturing endpoints and similar can be found here (read it if you are going to ask about it).
  • You can delete this section after reading it.

Form

Put an [x] if you meet the condition, else leave [ ].

Question

A specific question, so it’s understandable to anyone. You may add pictures.

YOUR QUESTION HERE I was working on this function, it’s bassed on the given example in docs:

require("dotenv").config();
const fs = require('fs');
const { IgApiClient } = require("instagram-private-api");
const ig = new IgApiClient();
const username = process.env.IG_USERNAME;
const password = process.env.IG_PASSWORD;
ig.state.generateDevice(username);

const dataCheck = function (callback) {
  fs.readFile('login_data.json', function (err, data) {
    console.log(data);
    if (data.length > 0) {
      callback(true);
    } else {
      callback(false);
    }
  });
}

const dataLoad = function (callback) {
  fs.readFile('login_data.json', function (err, data) {
      console.log("Read JSON file: " + data);
      data = JSON.parse(JSON.stringify(data));
      console.log("Object: " + data);
      callback(data);
  });
}

function dataSave(data){
  console.log("saving...");
  fs.writeFile("login_data.json", JSON.stringify(data),    function(err) {
    if(err) {
      console.log(err);
    }
    console.log("The file was saved!");
  }); 
}

igLogin();

async function igLogin(){

  await ig.simulate.preLoginFlow();

  ig.request.end$.subscribe(async () => {
    const serialized = await ig.state.serialize();
    delete serialized.constants;
    dataSave(serialized);
  });
  
  dataCheck(async dataExists => {
    console.log(dataExists);
    if (dataExists){
      dataLoad(async data => {
        ig.state.deserialize(data);
      }); 
    }
  });

  const auth = await ig.account.login(username, password);
  console.log(auth);
  
  process.nextTick(async () => await ig.simulate.postLoginFlow());

}

It can save the login data as a json file, It can login, but on the Instagram login activity it appears as a new login activity and not an old session. So, where is the mistake?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:35

github_iconTop GitHub Comments

1reaction
Ho3einWavecommented, Jan 30, 2022

Hi, I had the same issues that load session returns Cookie "ds_user_id" not found. I found it because I changed the API version in core/constants.js; it won’t return the cookies in session. Replace APP_VERSION with “121.0.0.29.119” and APP_VERSION_CODE with “185203708” and create a session again. I hope this helps you guys.

1reaction
Nerixyzcommented, Jan 30, 2020

@SaliZumberi Please paste your debug output here inside of code tags.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Session variables not working php - Stack Overflow
Maybe if your session path is not working properly you can try session.save_path(path/to/any folder); function as alternative path.
Read more >
session_start - Manual - PHP
session_start() creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed...
Read more >
PHP Sessions explained - Alex Web Develop
The first thing you need to do in your PHP script is to start a Session with the session_start() function. Every single remote...
Read more >
Why isn't my session state working in ASP.NET Core? Session ...
In this post I describe why session state appears to not work in ASP.NET Core 2.1+ apps, discuss the GDPR features, and how...
Read more >
PHP Sessions - W3Schools
What is a PHP Session? When you work with an application, you open it, do some changes, ... A session is started with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found