Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login is erroring (_sharedData) #291

Open
MGDproductions opened this issue Jun 2, 2022 · 35 comments
Open

Login is erroring (_sharedData) #291

MGDproductions opened this issue Jun 2, 2022 · 35 comments

Comments

@MGDproductions
Copy link

MGDproductions commented Jun 2, 2022

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.

@dreimert
Copy link

dreimert commented Jun 2, 2022

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

@AlexXmartlabs
Copy link

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

@batuhan-demir
Copy link

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

@TotalLag
Copy link

TotalLag commented Jun 4, 2022

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.

@PradyumnaCharate
Copy link

@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
Copy link

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
Copy link

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?

@galinowski
Copy link

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

@batuhan-demir
Copy link

batuhan-demir commented Jun 10, 2022

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

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

@alemens
Copy link

alemens commented Jun 12, 2022

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

@farizstuff
Copy link

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 ?

@7ruth
Copy link

7ruth commented Jun 30, 2022

+1

@SirMacke
Copy link

SirMacke commented Jul 2, 2022

Same issue...

@CryptoDevWill
Copy link

Still no answer to this?

@cruzjone-flexion
Copy link

+1

@Asadaaaaa
Copy link

+1

what do u mean +1?

@CryptoDevWill
Copy link

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

@csan-dev
Copy link

+1

@heyjustinai
Copy link

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

@Asadaaaaa
Copy link

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

@neumicha
Copy link

neumicha commented Jul 30, 2022

+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.

@Uniferdev
Copy link

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

@Freccia
Copy link

Freccia commented Oct 9, 2022

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 ?

@hunghuuk
Copy link

+1

@hydrix9
Copy link

hydrix9 commented Oct 27, 2022

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:
instaloader/instaloader#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

@vineethvijayan314
Copy link

@hydrix9 you are a gem 💎💎💎

@hydrix9
Copy link

hydrix9 commented Oct 28, 2022

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
Copy link

hydrix9 commented Oct 29, 2022

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

@ardinusawan
Copy link

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");

@Chodum91
Copy link

@Chodum91
Copy link

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":1007698095}}},"lid":"7245399117884480117"}

@Chodum91
Copy link

@mkbakhtiar
Copy link

try replace your lib/index,js with this files :

https://github.com/amamenko/inky-doodle/blob/master/instagram-web-api/index.js

@mkbakhtiar
Copy link

try replace your lib/index,js with this files :

https://github.com/amamenko/inky-doodle/blob/master/instagram-web-api/index.js

after running for call function getPhotosByUsername so result for this :

{
  user: {
    edge_owner_to_timeline_media: { count: 631, page_info: [Object], edges: [Array] }
  }
}

@janoist1
Copy link

try replace your lib/index,js with this files :

https://github.com/amamenko/inky-doodle/blob/master/instagram-web-api/index.js

I'm unable to login. 403 error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests