instagram-web-api icon indicating copy to clipboard operation
instagram-web-api copied to clipboard

Login is erroring (_sharedData)

Open MGDproductions opened this issue 3 years ago • 35 comments

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.

MGDproductions avatar Jun 02 '22 15:06 MGDproductions

Same problem. Fix _sharedData = false works for me too.

dreimert avatar Jun 02 '22 21:06 dreimert

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

AlexXmartlabs avatar Jun 03 '22 22:06 AlexXmartlabs

i have same issue and changing sharedvalue to false is fixing only login issue. i cant still fetch user profiles and etc

batuhan-demir avatar Jun 04 '22 17:06 batuhan-demir

I think instagram moved the object from being loaded with the page to now being lazy loaded, I'm not sure. The object still exists to the browser.

EDIT:

Looks like a problem with x-instagram-gis being undefined.

for (;;);{"__ar":1,"error":1357004,"errorSummary":"Sorry, something went wrong","errorDescription":"Please try closing and re-opening your browser window.","payload":null,"hsrp":{"hblp":{"consistency":{"rev":1005633177}}},"lid":"7105580147317749642"}

rhx_gis does not seem to be part of _sharedData anymore.

TotalLag avatar Jun 04 '22 21:06 TotalLag

@MDproductions-dev
Hello sir,I was also having same issue(_sharedData) and you solved my issue.Thank you so much.You seem expert in this. Also I was having one more issue.Do you have any solution on challenge urls? when i am getting followers list sometimes it asks me challenge and then i have to manually enter otp by going to challenge url in browser... Please help me if you can.I will be very thankfull

PradyumnaCharate avatar Jun 06 '22 07:06 PradyumnaCharate

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. Hello sir,I was also having same issue(_sharedData) and you solved my issue.Thank you so much.You seem expert in this. Also I was having one more issue.Do you have any solution on challenge urls? when i am getting followers list sometimes it asks me challenge and then i have to manually enter otp by going to challenge url in browser... Please help me if you can.I will be very thankfull

PradyumnaCharate avatar Jun 06 '22 07:06 PradyumnaCharate

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?

PradyumnaCharate avatar Jun 06 '22 07:06 PradyumnaCharate

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 })

galinowski avatar Jun 10 '22 08:06 galinowski

client.login({ username: username, password: password }, { _sharedData: false })

This allows to login but we cant still use functions like GetUserByUsername

batuhan-demir avatar Jun 10 '22 10:06 batuhan-demir

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

alemens avatar Jun 12 '22 21:06 alemens

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.

I tried this approach but sadly its not working, any updates from you @jlobos ?

farizstuff avatar Jun 20 '22 10:06 farizstuff

+1

7ruth avatar Jun 30 '22 17:06 7ruth

Same issue...

SirMacke avatar Jul 02 '22 13:07 SirMacke

Still no answer to this?

CryptoDevWill avatar Jul 05 '22 16:07 CryptoDevWill

+1

cruzjone-flexion avatar Jul 07 '22 03:07 cruzjone-flexion

+1

what do u mean +1?

Asadaaaaa avatar Jul 10 '22 10:07 Asadaaaaa

I think +1 means that person is having the same issue.

CryptoDevWill avatar Jul 13 '22 16:07 CryptoDevWill

+1

csan-dev avatar Jul 15 '22 00:07 csan-dev

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

heyjustinai avatar Jul 17 '22 06:07 heyjustinai

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

Asadaaaaa avatar Jul 20 '22 15:07 Asadaaaaa

+1

Tried with Creator and Personal account... Always getting the split error mentioned above.

TypeError: Cannot read property 'split' of undefined at ...\node_modules\instagram-web-api\lib\index.js:109:55 at processTicksAndRejections (internal/process/task_queues.js:95:5) at async Instagram.login (...\node_modules\instagram-web-api\lib\index.js:100:26)
at async start (...\src\main.js:20:5)

Setting _sharedData = false in index.js (line 48) means that my program runs without exception, but still my minimalistic program doesn't fetch my profile:

async function start() { try { await client.login(); const profile = await client.getProfile(); console.log(profile); } catch (e) { console.log("EXCEPTION"); console.log(e); } }

=> Prints undefined for profile Other functions such as .search seem to work, however.

neumicha avatar Jul 30 '22 13:07 neumicha

Has anyone found a way out of this situation or any workaround?

Uniferdev avatar Aug 19 '22 15:08 Uniferdev

Hello,

After trying to fix the issue with _sharedData = false as suggested I get this error:

$ node index.js 
/Users/user/code/instagram-autopost-bot/node_modules/instagram-web-api/lib/index.js:57
      value = matches[0].substring(13)
                     ^

TypeError: Cannot read properties of null (reading '0')
    at /Users/user/code/instagram-autopost-bot/node_modules/instagram-web-api/lib/index.js:57:22
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Instagram.login (/Users/user/code/instagram-autopost-bot/node_modules/instagram-web-api/lib/index.js:54:5)

Node.js v18.10.0

any idea how to fix ?

Freccia avatar Oct 09 '22 11:10 Freccia

+1

hunghuuk avatar Oct 24 '22 16:10 hunghuuk

seems like instagram changed their code a couple months ago, found this fix on another app though for same issue (no shared data): https://github.com/arc298/instagram-scraper/pull/809

another relevant post: https://github.com/instaloader/instaloader/issues/1553

update: Some data is now located at "https://i.instagram.com/api/v1/users/web_profile_info/?username=myUserName", then the json data is under ['data']['user'] if I am reading that pull request right, however this involves changing the baseUrl to i.instagram.com which breaks everything

also this endpoint fails to load if the useragent is not instagram based-- e.g. "Mozilla/5.0 (iPhone; CPU iPhone OS 15_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 Instagram 244.0.0.12.112 (iPhone12,1; iOS 15_5; en_US; en-US; scale=2.00; 828x1792; 383361019)"

update 2: I've gotten past the login, now that just leaves... everything else in the plugin https://github.com/hydrix9/instagram-web-api/blob/master/lib/index.js mainly all the URLs seem to be scrambled this is extremely rough, I apologize for butchering this code

hydrix9 avatar Oct 27 '22 19:10 hydrix9

@hydrix9 you are a gem 💎💎💎

vineethvijayan314 avatar Oct 28 '22 19:10 vineethvijayan314

I managed to get follow and unfollow working https://github.com/hydrix9/instagram-web-api/blob/master/lib/index.js

it seems like all the /web/ urls are now at i.instagram.com/api/v1/web/ approve, ignore, block, unblock, like, unlike, save, unsave, and search might also be working but I haven't tested it yet

In my code I removed _getGis and _getSharedData since those were only being used for getUserByUsername. In my code getUserByUsername now returns the results from https://i.instagram.com/api/v1/users/web_profile_info/?username=myUserName

I'm working on uploadPhoto, I had to add the followeAllRedirects=true option to prevent a 302 error (not sure where it redirects) also the response seemed to be gzipped, which was solved by adding the gzip=true option gzip might be needed to be turned off if it does start returning json right now its returning html of a blank page instead of json containing the upload_id we need to do part 2 in uploadPhoto however on the web interface, when doing the request it returns the json as expected not sure where to go from here, I tried adding 'form' data like you see in the POST request on the web interface when posting an image, but that caused it to start giving socket hang up error instead

I'll have more time to work on this in a couple days, if anyone wants to fix something that's giving a 404 page on request try adding baseUrl: baseUrlApi to the request options to use the i.instagram.com/web/api/ base url instead in my code. I was able to find which url to use by going on the web interface and performing an action and watching the post requests with ctrl-shift-i -> networking on firefox

update: I think I found the correct url now for uploadPhoto at "https://i.instagram.com/rupload_igphoto/fb_uploader_{myId}" instead of "instagram.com/rupload_igphoto/{myDate}_0_{myId}" and it's giving a '403 login required' instead of the error above, so looks promising

hydrix9 avatar Oct 28 '22 21:10 hydrix9

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 avatar Oct 29 '22 22:10 hydrix9

For everyone who looking for solution: Based on this youtube desc: https://www.youtube.com/watch?v=XzyYi_yv86A

  1. Create an empty directory in the root of your app called "instagram-web-api"
  2. Copy the index.js file from my GitHub repo (https://github.com/amamenko/inky-dood... into that directory.
  3. Substitute your current import of the "Instagram" object from the instagram-web-api library in your app with const Instagram = require("./instagram-web-api/index");

ardinusawan avatar Jun 01 '23 04:06 ardinusawan

www.facebook.com1007698095-7245399117884480117

Chodum91 avatar Jun 16 '23 21:06 Chodum91