instagram-web-api: Login is erroring (_sharedData)

This api has been working fine for over a year for me now but since yesterday i have been getting this error:


/home/container/node_modules/instagram-web-api/lib/index.js:109
        html => html.split('window._sharedData = ')[1].split(';</script>')[0]
                                                      ^
TypeError: Cannot read properties of undefined (reading 'split')
    at /home/container/node_modules/instagram-web-api/lib/index.js:109:55
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Instagram.login (/home/container/node_modules/instagram-web-api/lib/index.js:100:26)

I fixed it myself (somehow) by setting _sharedData to false at line 48 of /lib/index.js I don’t know what this does or if it is important to have on so might as well make an issue.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 14
  • Comments: 35

Most upvoted comments

If you don’t want to modify the source code, you may call login with {_sharedData: false} as an argument:

const Instagram = require(‘instagram-web-api’) const client = new Instagram({username, password}) await client.login({ username: username, password: password }, { _sharedData: false })

This api has been working fine for over a year for me now but since yesterday i have been getting this error:


/home/container/node_modules/instagram-web-api/lib/index.js:109
        html => html.split('window._sharedData = ')[1].split(';</script>')[0]
                                                      ^
TypeError: Cannot read properties of undefined (reading 'split')
    at /home/container/node_modules/instagram-web-api/lib/index.js:109:55
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Instagram.login (/home/container/node_modules/instagram-web-api/lib/index.js:100:26)

I fixed it myself (somehow) by setting _sharedData to false at line 48 of /lib/index.js I don’t know what this does or if it is important to have on so might as well make an issue.

Unfortunately you didn’t fix anything you just do not load data. Instead lib needs edits accordingly to the new Instagram GraphQL API format. In fact if you do a View Page Source on a instagram profile and search for _sharedData you do not get any result.

@jlobos Lobito are you still interested in this library? We need your support to update it

I had the same issue, switching it to a personal account (from a business/creator acc) seem to do the trick

mine is personal account but still error

Same here. This workaround will let us login, but if we want to use getPhotosByUsername we still need the sharedData value…

I got uploadPhoto working https://github.com/hydrix9/instagram-web-api/blob/master/lib/index.js bad news, https://i.instagram.com/rupload_igphoto/fb_uploader_{myId} takes a sessionid cookie now or it will redirect you to a login page, which explains why it was giving the 302 error with a gzipped html page before worse news, its generated on the client on login and I’m not sure how to reverse engineer it I managed to find the sessionid code here: https://static.cdninstagram.com/rsrc.php/v3iF2k4/y-/l/en_US/dY3zq_4wAbs.js?_nc_x=Ij3Wp8lg5Kz it has a function called getSessionID which returns this.getTabId() + ":" + this.getPageId() + ":" + this.getTransitionId() + "-" + this.getActivityId() I gave a shot at generating it with getNewSessionId in my code but it didn’t work for me, seems to be a little more than random numbers there’s another cookie generated on client called x-ig-www-claim but I don’t think we need it my hackish fix right now is to simply login on instagram.com and find the sessionid under ctrl-shift-i (on firefox) -> storage -> cookies -> instagram.com -> session id and copy that, the cookie should be good for a year at least

anyways this is way out of scope of the original error, but I got the three major functions I needed working and I wish you luck on fixing the rest of the functions

@hydrix9 you are a gem 💎💎💎

I think instagram moved the object from being loade

Sir do you have any idea then how can we get likes by photos if shared data is false?