Coder Social home page Coder Social logo

Comments (15)

Strooss avatar Strooss commented on June 3, 2024 1

I think the issue is with this code new RegExp(/(csrf_token":")\w+/). It expects the quotes to not be escaped.

Doing a console.log(res.toJSON().body) ... I can see 2 matches for csrf_token ... the first one contains the actual value, but has the quotes escaped -> csrf_token\":\"...\" ... the second one is not escaped, but the value is empty -> csrf_token":"".

The way I got it to work was to replace escaped quotes with non-escaped ones, before matching the regex:

await this.request('/', { resolveWithFullResponse: true }).then(res => {
      const pattern = new RegExp(/(csrf_token":")\w+/)
      const matches = res.toJSON().body.replace(/\\"/g, '"').match(pattern)
      value = matches[0].substring(13)
    })

i think the package is completely broken..

from instagram-web-api.

larkrak avatar larkrak commented on June 3, 2024 1

but this creates a new error if u tried running it a request error

can you give the error you got?

I think the previous guy is talking about this error:

photo_2023-05-28_21-10-49

Which is happening to me after your fix. I inspected all the output from this function:
343a76dd80e8eb90b9a8aa876810b853
Saving it in a file and looking for "window._sharedData" which is the split condition, and there is no "window._sharedData" on that html string.

Is this some change from instagram? Do we know a fix for this?

from instagram-web-api.

Strooss avatar Strooss commented on June 3, 2024

having the same issue here..

from instagram-web-api.

ColdFire87 avatar ColdFire87 commented on June 3, 2024

I think the issue is with this code new RegExp(/(csrf_token":")\w+/). It expects the quotes to not be escaped.

Doing a console.log(res.toJSON().body) ... I can see 2 matches for csrf_token ... the first one contains the actual value, but has the quotes escaped -> csrf_token\":\"...\" ... the second one is not escaped, but the value is empty -> csrf_token":"".

The way I got it to work was to replace escaped quotes with non-escaped ones, before matching the regex:

await this.request('/', { resolveWithFullResponse: true }).then(res => {
      const pattern = new RegExp(/(csrf_token":")\w+/)
      const matches = res.toJSON().body.replace(/\\"/g, '"').match(pattern)
      value = matches[0].substring(13)
    })

from instagram-web-api.

dimaspriyanto avatar dimaspriyanto commented on June 3, 2024

For my case, Instagram identify unusual login, when i follow the checkpoint URL, they required me to change my password before continue..

StatusCodeError: 400 - {"message":"checkpoint_required","checkpoint_url":"/challenge/action/AXEKy63B9j8ILsr8huijpQn9PEYOzBiY-5vpbN6PDFgowATNdyZrUX1VXivUQaLV-JTF/Afz24OgDEt9wmXbBpuUFsCytJ_mtvkP7OT3aYhJEtJZtsy0dtVT1_qlvE426vXD6vBgLMIO8u-OUVw/ffc_UEvY9OEISw45TL7Pr9Uu6ASkxGOMKWYGuv7xl3Jjodk40sV7IzWyJvaXH63VVOo1/","lock":false,"flow_render_type":0,"status":"fail"}

from instagram-web-api.

AliAryanTech avatar AliAryanTech commented on June 3, 2024
TypeError: Cannot read properties of null (reading '0')

++

from instagram-web-api.

technical-shoubhik avatar technical-shoubhik commented on June 3, 2024

(node:2668) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '0' of null
at D:\Codes\NodeJS\ins\node_modules\instagram-web-api\lib\index.js:57:22
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async Instagram.login (D:\Codes\NodeJS\ins\node_modules\instagram-web-api\lib\index.js:54:5)
(Use node --trace-warnings ... to show where the warning was created)
(node:2668) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2668) [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.

from instagram-web-api.

quaint-racoon avatar quaint-racoon commented on June 3, 2024

Dude 2 months still not solved

from instagram-web-api.

erhancan256 avatar erhancan256 commented on June 3, 2024

Dude 2 months still not solved

i have same problem pls help

from instagram-web-api.

quaint-racoon avatar quaint-racoon commented on June 3, 2024

I found a solution but theres another porblem

Edit the package and replace the errored code with this

let value = this.request('/', { resolveWithFullResponse: true }).then(res => {
const pattern = new RegExp(/(csrf_token\":\")[\w]+/)
const matches = res.body.match(pattern)
value = matches[0].substring(15)
})

But another error apears

from instagram-web-api.

dmzoneill avatar dmzoneill commented on June 3, 2024

just tried to use the moduile and hit this also

Apr 04 19:17:51 dave-pc node[1278826]:       value = matches[0].substring(13)
Apr 04 19:17:51 dave-pc node[1278826]:                      ^
Apr 04 19:17:51 dave-pc node[1278826]: TypeError: Cannot read properties of null (reading '0')
Apr 04 19:17:51 dave-pc node[1278826]:     at /home/dave/src/whatsbot/node_modules/instagram-web-api/lib/index.js:57:22
Apr 04 19:17:51 dave-pc node[1278826]:     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Apr 04 19:17:51 dave-pc node[1278826]:     at async Instagram.login (/home/dave/src/whatsbot/node_modules/instagram-web-api/lib/index.js:54:5)

disappointing

from instagram-web-api.

SGauts avatar SGauts commented on June 3, 2024

Facing the same issue.
value = matches[0].substring(13) ^ TypeError: Cannot read properties of null (reading '0')
Any fix ?

from instagram-web-api.

alexandre-hallaine avatar alexandre-hallaine commented on June 3, 2024

i made a fix, just replace this

    let value
    await this.request('/', { resolveWithFullResponse: true }).then(res => {
      const pattern = new RegExp(/(csrf_token":")\w+/)
      const matches = res.toJSON().body.match(pattern)
      value = matches[0].substring(13)
    })

with this

    let value
    await this.request('/', { resolveWithFullResponse: true }).then(res => {
      const pattern = new RegExp(/(csrf_token\\":\\")\w+/)
      const matches = res.toJSON().body.match(pattern)
      if (!matches || matches.length === 0)
        throw new Error('Missing CSRFToken')
      value = matches[0].substring(15)
    })

in the file lib/index.js line 53

from instagram-web-api.

quaint-racoon avatar quaint-racoon commented on June 3, 2024

i made a fix, just replace this

    let value
    await this.request('/', { resolveWithFullResponse: true }).then(res => {
      const pattern = new RegExp(/(csrf_token":")\w+/)
      const matches = res.toJSON().body.match(pattern)
      value = matches[0].substring(13)
    })

with this

    let value
    await this.request('/', { resolveWithFullResponse: true }).then(res => {
      const pattern = new RegExp(/(csrf_token\\":\\")\w+/)
      const matches = res.toJSON().body.match(pattern)
      if (!matches || matches.length === 0)
        throw new Error('Missing CSRFToken')
      value = matches[0].substring(15)
    })

in the file lib/index.js line 53

but this creates a new error if u tried running it a request error

from instagram-web-api.

alexandre-hallaine avatar alexandre-hallaine commented on June 3, 2024

but this creates a new error if u tried running it a request error

can you give the error you got?

from instagram-web-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.